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
|
// Copyright 2024 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package queue
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPlainQueue(t *testing.T) {
pq := Plain()
req1, req2, req3 := &Request{}, &Request{}, &Request{}
pq.Submit(req1)
pq.Submit(req2)
assert.Equal(t, req1, pq.Next())
assert.Equal(t, req2, pq.Next())
pq.Submit(req3)
assert.Equal(t, req3, pq.Next())
assert.Nil(t, pq.Next())
}
func TestPrioQueue(t *testing.T) {
req1, req2, req3, req4 :=
&Request{}, &Request{}, &Request{}, &Request{}
pq := DynamicOrder()
pq1 := pq.Append()
pq2 := pq.Append()
pq3 := pq.Append()
pq2.Submit(req2)
pq3.Submit(req3)
assert.Equal(t, req2, pq.Next())
pq1.Submit(req1)
assert.Equal(t, req1, pq.Next())
pq2.Submit(req4)
assert.Equal(t, req4, pq.Next())
assert.Equal(t, req3, pq.Next())
}
|