1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 func TestRandomScheduler(t *testing.T) {
10 ws := NewRandomWriteScheduler()
11 ws.Push(makeWriteHeadersRequest(3))
12 ws.Push(makeWriteHeadersRequest(4))
13 ws.Push(makeWriteHeadersRequest(1))
14 ws.Push(makeWriteHeadersRequest(2))
15 ws.Push(makeWriteNonStreamRequest())
16 ws.Push(makeWriteNonStreamRequest())
18 // Pop all frames. Should get the non-stream requests first,
19 // followed by the stream requests in any order.
20 var order []FrameWriteRequest
26 order = append(order, wr)
28 t.Logf("got frames: %v", order)
30 t.Fatalf("got %d frames, expected 6", len(order))
32 if order[0].StreamID() != 0 || order[1].StreamID() != 0 {
33 t.Fatal("expected non-stream frames first", order[0], order[1])
35 got := make(map[uint32]bool)
36 for _, wr := range order[2:] {
37 got[wr.StreamID()] = true
39 for id := uint32(1); id <= 4; id++ {
41 t.Errorf("frame not found for stream %d", id)