forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_test.go
95 lines (92 loc) · 1.93 KB
/
state_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
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
package das
import (
"errors"
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_coordinatorStats(t *testing.T) {
tests := []struct {
name string
state *coordinatorState
want SamplingStats
}{
{
"basic",
&coordinatorState{
inProgress: map[int]func() workerState{
1: func() workerState {
return workerState{
result: result{
job: job{
jobType: recentJob,
from: 21,
to: 30,
},
failed: map[uint64]int{22: 1},
err: errors.New("22: failed"),
},
curr: 25,
}
},
2: func() workerState {
return workerState{
result: result{
job: job{
jobType: catchupJob,
from: 11,
to: 20,
},
failed: map[uint64]int{12: 1, 13: 1},
err: errors.Join(errors.New("12: failed"), errors.New("13: failed")),
},
curr: 15,
}
},
},
failed: map[uint64]retryAttempt{
22: {count: 1},
23: {count: 1},
24: {count: 2},
},
nextJobID: 0,
next: 31,
networkHead: 100,
},
SamplingStats{
SampledChainHead: 11,
CatchupHead: 30,
NetworkHead: 100,
Failed: map[uint64]int{22: 2, 23: 1, 24: 2, 12: 1, 13: 1},
Workers: []WorkerStats{
{
JobType: recentJob,
Curr: 25,
From: 21,
To: 30,
ErrMsg: "22: failed",
},
{
JobType: catchupJob,
Curr: 15,
From: 11,
To: 20,
ErrMsg: "12: failed\n13: failed",
},
},
Concurrency: 2,
CatchUpDone: false,
IsRunning: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stats := tt.state.unsafeStats()
sort.Slice(stats.Workers, func(i, j int) bool {
return stats.Workers[i].From > stats.Workers[j].Curr
})
assert.Equal(t, tt.want, stats, "stats are not equal")
})
}
}