-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus_test.go
60 lines (46 loc) · 1.04 KB
/
status_test.go
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
package block_stm
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestStatusBasics(t *testing.T) {
s := makeStatusManager(10)
x := s.takeNextPending()
require.Equal(t, 0, x)
require.True(t, s.checkInProgress(x))
x = s.takeNextPending()
require.Equal(t, 1, x)
s.markComplete(0)
require.False(t, s.checkInProgress(0))
require.Equal(t, 0, s.maxAllComplete())
x = s.takeNextPending()
require.Equal(t, 2, x)
s.markComplete(x)
require.False(t, s.checkInProgress(2))
require.Equal(t, 0, s.maxAllComplete(), "zero should still be min complete")
}
func TestMaxComplete(t *testing.T) {
s := makeStatusManager(10)
for {
tx := s.takeNextPending()
if tx == -1 {
break
}
if tx != 7 {
s.markComplete(tx)
}
}
require.Equal(t, 6, s.maxAllComplete())
s2 := makeStatusManager(10)
for {
tx := s2.takeNextPending()
if tx == -1 {
break
}
}
s2.markComplete(2)
s2.markComplete(4)
require.Equal(t, -1, s2.maxAllComplete())
s2.complete = insertInList(s2.complete, 4)
require.Equal(t, 2, s2.countComplete())
}