writesched_priority_test.go 17.1 KB
Newer Older
zhangweiwei's avatar
init  
zhangweiwei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package http2

import (
	"bytes"
	"fmt"
	"sort"
	"testing"
)

func defaultPriorityWriteScheduler() *priorityWriteScheduler {
	return NewPriorityWriteScheduler(nil).(*priorityWriteScheduler)
}

func checkPriorityWellFormed(ws *priorityWriteScheduler) error {
	for id, n := range ws.nodes {
		if id != n.id {
			return fmt.Errorf("bad ws.nodes: ws.nodes[%d] = %d", id, n.id)
		}
		if n.parent == nil {
			if n.next != nil || n.prev != nil {
				return fmt.Errorf("bad node %d: nil parent but prev/next not nil", id)
			}
			continue
		}
		found := false
		for k := n.parent.kids; k != nil; k = k.next {
			if k.id == id {
				found = true
				break
			}
		}
		if !found {
			return fmt.Errorf("bad node %d: not found in parent %d kids list", id, n.parent.id)
		}
	}
	return nil
}

func fmtTree(ws *priorityWriteScheduler, fmtNode func(*priorityNode) string) string {
	var ids []int
	for _, n := range ws.nodes {
		ids = append(ids, int(n.id))
	}
	sort.Ints(ids)

	var buf bytes.Buffer
	for _, id := range ids {
		if buf.Len() != 0 {
			buf.WriteString(" ")
		}
		if id == 0 {
			buf.WriteString(fmtNode(&ws.root))
		} else {
			buf.WriteString(fmtNode(ws.nodes[uint32(id)]))
		}
	}
	return buf.String()
}

func fmtNodeParentSkipRoot(n *priorityNode) string {
	switch {
	case n.id == 0:
		return ""
	case n.parent == nil:
		return fmt.Sprintf("%d{parent:nil}", n.id)
	default:
		return fmt.Sprintf("%d{parent:%d}", n.id, n.parent.id)
	}
}

func fmtNodeWeightParentSkipRoot(n *priorityNode) string {
	switch {
	case n.id == 0:
		return ""
	case n.parent == nil:
		return fmt.Sprintf("%d{weight:%d,parent:nil}", n.id, n.weight)
	default:
		return fmt.Sprintf("%d{weight:%d,parent:%d}", n.id, n.weight, n.parent.id)
	}
}

func TestPriorityTwoStreams(t *testing.T) {
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{})

	want := "1{weight:15,parent:0} 2{weight:15,parent:0}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After open\ngot  %q\nwant %q", got, want)
	}

	// Move 1's parent to 2.
	ws.AdjustStream(1, PriorityParam{
		StreamDep: 2,
		Weight:    32,
		Exclusive: false,
	})
	want = "1{weight:32,parent:2} 2{weight:15,parent:0}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}

	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPriorityAdjustExclusiveZero(t *testing.T) {
	// 1, 2, and 3 are all children of the 0 stream.
	// Exclusive reprioritization to any of the streams should bring
	// the rest of the streams under the reprioritized stream.
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{})
	ws.OpenStream(3, OpenStreamOptions{})

	want := "1{weight:15,parent:0} 2{weight:15,parent:0} 3{weight:15,parent:0}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After open\ngot  %q\nwant %q", got, want)
	}

	ws.AdjustStream(2, PriorityParam{
		StreamDep: 0,
		Weight:    20,
		Exclusive: true,
	})
	want = "1{weight:15,parent:2} 2{weight:20,parent:0} 3{weight:15,parent:2}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}

	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPriorityAdjustOwnParent(t *testing.T) {
	// Assigning a node as its own parent should have no effect.
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{})
	ws.AdjustStream(2, PriorityParam{
		StreamDep: 2,
		Weight:    20,
		Exclusive: true,
	})
	want := "1{weight:15,parent:0} 2{weight:15,parent:0}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPriorityClosedStreams(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{MaxClosedNodesInTree: 2}).(*priorityWriteScheduler)
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 2})
	ws.OpenStream(4, OpenStreamOptions{PusherID: 3})

	// Close the first three streams. We lose 1, but keep 2 and 3.
	ws.CloseStream(1)
	ws.CloseStream(2)
	ws.CloseStream(3)

	want := "2{weight:15,parent:0} 3{weight:15,parent:2} 4{weight:15,parent:3}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After close\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}

	// Adding a stream as an exclusive child of 1 gives it default
	// priorities, since 1 is gone.
	ws.OpenStream(5, OpenStreamOptions{})
	ws.AdjustStream(5, PriorityParam{StreamDep: 1, Weight: 15, Exclusive: true})

	// Adding a stream as an exclusive child of 2 should work, since 2 is not gone.
	ws.OpenStream(6, OpenStreamOptions{})
	ws.AdjustStream(6, PriorityParam{StreamDep: 2, Weight: 15, Exclusive: true})

	want = "2{weight:15,parent:0} 3{weight:15,parent:6} 4{weight:15,parent:3} 5{weight:15,parent:0} 6{weight:15,parent:2}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After add streams\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPriorityClosedStreamsDisabled(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{}).(*priorityWriteScheduler)
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 2})

	// Close the first two streams. We keep only 3.
	ws.CloseStream(1)
	ws.CloseStream(2)

	want := "3{weight:15,parent:0}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After close\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPriorityIdleStreams(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{MaxIdleNodesInTree: 2}).(*priorityWriteScheduler)
	ws.AdjustStream(1, PriorityParam{StreamDep: 0, Weight: 15}) // idle
	ws.AdjustStream(2, PriorityParam{StreamDep: 0, Weight: 15}) // idle
	ws.AdjustStream(3, PriorityParam{StreamDep: 2, Weight: 20}) // idle
	ws.OpenStream(4, OpenStreamOptions{})
	ws.OpenStream(5, OpenStreamOptions{})
	ws.OpenStream(6, OpenStreamOptions{})
	ws.AdjustStream(4, PriorityParam{StreamDep: 1, Weight: 15})
	ws.AdjustStream(5, PriorityParam{StreamDep: 2, Weight: 15})
	ws.AdjustStream(6, PriorityParam{StreamDep: 3, Weight: 15})

	want := "2{weight:15,parent:0} 3{weight:20,parent:2} 4{weight:15,parent:0} 5{weight:15,parent:2} 6{weight:15,parent:3}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After open\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPriorityIdleStreamsDisabled(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{}).(*priorityWriteScheduler)
	ws.AdjustStream(1, PriorityParam{StreamDep: 0, Weight: 15}) // idle
	ws.AdjustStream(2, PriorityParam{StreamDep: 0, Weight: 15}) // idle
	ws.AdjustStream(3, PriorityParam{StreamDep: 2, Weight: 20}) // idle
	ws.OpenStream(4, OpenStreamOptions{})

	want := "4{weight:15,parent:0}"
	if got := fmtTree(ws, fmtNodeWeightParentSkipRoot); got != want {
		t.Errorf("After open\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPrioritySection531NonExclusive(t *testing.T) {
	// Example from RFC 7540 Section 5.3.1.
	// A,B,C,D = 1,2,3,4
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(4, OpenStreamOptions{})
	ws.AdjustStream(4, PriorityParam{
		StreamDep: 1,
		Weight:    15,
		Exclusive: false,
	})
	want := "1{parent:0} 2{parent:1} 3{parent:1} 4{parent:1}"
	if got := fmtTree(ws, fmtNodeParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPrioritySection531Exclusive(t *testing.T) {
	// Example from RFC 7540 Section 5.3.1.
	// A,B,C,D = 1,2,3,4
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(4, OpenStreamOptions{})
	ws.AdjustStream(4, PriorityParam{
		StreamDep: 1,
		Weight:    15,
		Exclusive: true,
	})
	want := "1{parent:0} 2{parent:4} 3{parent:4} 4{parent:1}"
	if got := fmtTree(ws, fmtNodeParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func makeSection533Tree() *priorityWriteScheduler {
	// Initial tree from RFC 7540 Section 5.3.3.
	// A,B,C,D,E,F = 1,2,3,4,5,6
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(4, OpenStreamOptions{PusherID: 3})
	ws.OpenStream(5, OpenStreamOptions{PusherID: 3})
	ws.OpenStream(6, OpenStreamOptions{PusherID: 4})
	return ws
}

func TestPrioritySection533NonExclusive(t *testing.T) {
	// Example from RFC 7540 Section 5.3.3.
	// A,B,C,D,E,F = 1,2,3,4,5,6
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(4, OpenStreamOptions{PusherID: 3})
	ws.OpenStream(5, OpenStreamOptions{PusherID: 3})
	ws.OpenStream(6, OpenStreamOptions{PusherID: 4})
	ws.AdjustStream(1, PriorityParam{
		StreamDep: 4,
		Weight:    15,
		Exclusive: false,
	})
	want := "1{parent:4} 2{parent:1} 3{parent:1} 4{parent:0} 5{parent:3} 6{parent:4}"
	if got := fmtTree(ws, fmtNodeParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func TestPrioritySection533Exclusive(t *testing.T) {
	// Example from RFC 7540 Section 5.3.3.
	// A,B,C,D,E,F = 1,2,3,4,5,6
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(4, OpenStreamOptions{PusherID: 3})
	ws.OpenStream(5, OpenStreamOptions{PusherID: 3})
	ws.OpenStream(6, OpenStreamOptions{PusherID: 4})
	ws.AdjustStream(1, PriorityParam{
		StreamDep: 4,
		Weight:    15,
		Exclusive: true,
	})
	want := "1{parent:4} 2{parent:1} 3{parent:1} 4{parent:0} 5{parent:3} 6{parent:1}"
	if got := fmtTree(ws, fmtNodeParentSkipRoot); got != want {
		t.Errorf("After adjust\ngot  %q\nwant %q", got, want)
	}
	if err := checkPriorityWellFormed(ws); err != nil {
		t.Error(err)
	}
}

func checkPopAll(ws WriteScheduler, order []uint32) error {
	for k, id := range order {
		wr, ok := ws.Pop()
		if !ok {
			return fmt.Errorf("Pop[%d]: got ok=false, want %d (order=%v)", k, id, order)
		}
		if got := wr.StreamID(); got != id {
			return fmt.Errorf("Pop[%d]: got %v, want %d (order=%v)", k, got, id, order)
		}
	}
	wr, ok := ws.Pop()
	if ok {
		return fmt.Errorf("Pop[%d]: got %v, want ok=false (order=%v)", len(order), wr.StreamID(), order)
	}
	return nil
}

func TestPriorityPopFrom533Tree(t *testing.T) {
	ws := makeSection533Tree()

	ws.Push(makeWriteHeadersRequest(3 /*C*/))
	ws.Push(makeWriteNonStreamRequest())
	ws.Push(makeWriteHeadersRequest(5 /*E*/))
	ws.Push(makeWriteHeadersRequest(1 /*A*/))
	t.Log("tree:", fmtTree(ws, fmtNodeParentSkipRoot))

	if err := checkPopAll(ws, []uint32{0 /*NonStream*/, 1, 3, 5}); err != nil {
		t.Error(err)
	}
}

func TestPriorityPopFromLinearTree(t *testing.T) {
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})
	ws.OpenStream(3, OpenStreamOptions{PusherID: 2})
	ws.OpenStream(4, OpenStreamOptions{PusherID: 3})

	ws.Push(makeWriteHeadersRequest(3))
	ws.Push(makeWriteHeadersRequest(4))
	ws.Push(makeWriteHeadersRequest(1))
	ws.Push(makeWriteHeadersRequest(2))
	ws.Push(makeWriteNonStreamRequest())
	ws.Push(makeWriteNonStreamRequest())
	t.Log("tree:", fmtTree(ws, fmtNodeParentSkipRoot))

	if err := checkPopAll(ws, []uint32{0, 0 /*NonStreams*/, 1, 2, 3, 4}); err != nil {
		t.Error(err)
	}
}

func TestPriorityFlowControl(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{ThrottleOutOfOrderWrites: false})
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})

	sc := &serverConn{maxFrameSize: 16}
	st1 := &stream{id: 1, sc: sc}
	st2 := &stream{id: 2, sc: sc}

	ws.Push(FrameWriteRequest{&writeData{1, make([]byte, 16), false}, st1, nil})
	ws.Push(FrameWriteRequest{&writeData{2, make([]byte, 16), false}, st2, nil})
	ws.AdjustStream(2, PriorityParam{StreamDep: 1})

	// No flow-control bytes available.
	if wr, ok := ws.Pop(); ok {
		t.Fatalf("Pop(limited by flow control)=%v,true, want false", wr)
	}

	// Add enough flow-control bytes to write st2 in two Pop calls.
	// Should write data from st2 even though it's lower priority than st1.
	for i := 1; i <= 2; i++ {
		st2.flow.add(8)
		wr, ok := ws.Pop()
		if !ok {
			t.Fatalf("Pop(%d)=false, want true", i)
		}
		if got, want := wr.DataSize(), 8; got != want {
			t.Fatalf("Pop(%d)=%d bytes, want %d bytes", i, got, want)
		}
	}
}

func TestPriorityThrottleOutOfOrderWrites(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{ThrottleOutOfOrderWrites: true})
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{PusherID: 1})

	sc := &serverConn{maxFrameSize: 4096}
	st1 := &stream{id: 1, sc: sc}
	st2 := &stream{id: 2, sc: sc}
	st1.flow.add(4096)
	st2.flow.add(4096)
	ws.Push(FrameWriteRequest{&writeData{2, make([]byte, 4096), false}, st2, nil})
	ws.AdjustStream(2, PriorityParam{StreamDep: 1})

	// We have enough flow-control bytes to write st2 in a single Pop call.
	// However, due to out-of-order write throttling, the first call should
	// only write 1KB.
	wr, ok := ws.Pop()
	if !ok {
		t.Fatalf("Pop(st2.first)=false, want true")
	}
	if got, want := wr.StreamID(), uint32(2); got != want {
		t.Fatalf("Pop(st2.first)=stream %d, want stream %d", got, want)
	}
	if got, want := wr.DataSize(), 1024; got != want {
		t.Fatalf("Pop(st2.first)=%d bytes, want %d bytes", got, want)
	}

	// Now add data on st1. This should take precedence.
	ws.Push(FrameWriteRequest{&writeData{1, make([]byte, 4096), false}, st1, nil})
	wr, ok = ws.Pop()
	if !ok {
		t.Fatalf("Pop(st1)=false, want true")
	}
	if got, want := wr.StreamID(), uint32(1); got != want {
		t.Fatalf("Pop(st1)=stream %d, want stream %d", got, want)
	}
	if got, want := wr.DataSize(), 4096; got != want {
		t.Fatalf("Pop(st1)=%d bytes, want %d bytes", got, want)
	}

	// Should go back to writing 1KB from st2.
	wr, ok = ws.Pop()
	if !ok {
		t.Fatalf("Pop(st2.last)=false, want true")
	}
	if got, want := wr.StreamID(), uint32(2); got != want {
		t.Fatalf("Pop(st2.last)=stream %d, want stream %d", got, want)
	}
	if got, want := wr.DataSize(), 1024; got != want {
		t.Fatalf("Pop(st2.last)=%d bytes, want %d bytes", got, want)
	}
}

func TestPriorityWeights(t *testing.T) {
	ws := defaultPriorityWriteScheduler()
	ws.OpenStream(1, OpenStreamOptions{})
	ws.OpenStream(2, OpenStreamOptions{})

	sc := &serverConn{maxFrameSize: 8}
	st1 := &stream{id: 1, sc: sc}
	st2 := &stream{id: 2, sc: sc}
	st1.flow.add(40)
	st2.flow.add(40)

	ws.Push(FrameWriteRequest{&writeData{1, make([]byte, 40), false}, st1, nil})
	ws.Push(FrameWriteRequest{&writeData{2, make([]byte, 40), false}, st2, nil})
	ws.AdjustStream(1, PriorityParam{StreamDep: 0, Weight: 34})
	ws.AdjustStream(2, PriorityParam{StreamDep: 0, Weight: 9})

	// st1 gets 3.5x the bandwidth of st2 (3.5 = (34+1)/(9+1)).
	// The maximum frame size is 8 bytes. The write sequence should be:
	//   st1, total bytes so far is (st1=8,  st=0)
	//   st2, total bytes so far is (st1=8,  st=8)
	//   st1, total bytes so far is (st1=16, st=8)
	//   st1, total bytes so far is (st1=24, st=8)   // 3x bandwidth
	//   st1, total bytes so far is (st1=32, st=8)   // 4x bandwidth
	//   st2, total bytes so far is (st1=32, st=16)  // 2x bandwidth
	//   st1, total bytes so far is (st1=40, st=16)
	//   st2, total bytes so far is (st1=40, st=24)
	//   st2, total bytes so far is (st1=40, st=32)
	//   st2, total bytes so far is (st1=40, st=40)
	if err := checkPopAll(ws, []uint32{1, 2, 1, 1, 1, 2, 1, 2, 2, 2}); err != nil {
		t.Error(err)
	}
}

func TestPriorityRstStreamOnNonOpenStreams(t *testing.T) {
	ws := NewPriorityWriteScheduler(&PriorityWriteSchedulerConfig{
		MaxClosedNodesInTree: 0,
		MaxIdleNodesInTree:   0,
	})
	ws.OpenStream(1, OpenStreamOptions{})
	ws.CloseStream(1)
	ws.Push(FrameWriteRequest{write: streamError(1, ErrCodeProtocol)})
	ws.Push(FrameWriteRequest{write: streamError(2, ErrCodeProtocol)})

	if err := checkPopAll(ws, []uint32{1, 2}); err != nil {
		t.Error(err)
	}
}