-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbootstrap_delay_test.go
More file actions
86 lines (79 loc) · 2.56 KB
/
bootstrap_delay_test.go
File metadata and controls
86 lines (79 loc) · 2.56 KB
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
package f3
import (
"testing"
"time"
"github.com/filecoin-project/go-f3/ec"
"github.com/filecoin-project/go-f3/internal/clock"
"github.com/filecoin-project/go-f3/manifest"
)
var _ ec.TipSet = (*tipset)(nil)
func TestComputeBootstrapDelay(t *testing.T) {
period := 30 * time.Second
bootstrapEpoch := 1000
m := manifest.Manifest{
BootstrapEpoch: int64(bootstrapEpoch),
EC: manifest.EcConfig{
Period: period,
},
}
clock := clock.NewMock()
genesis := time.Date(2020, time.January, 12, 01, 01, 01, 00, time.UTC)
tt := []struct {
name string
time time.Time
ts tipset
want time.Duration
}{
{
name: "in sync - right before bootstrap",
time: genesis.Add(time.Duration(bootstrapEpoch-1) * period),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch - 1), period: period},
want: period,
},
{
name: "in sync - right at bootstrap",
time: genesis.Add(time.Duration(bootstrapEpoch) * period),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch), period: period},
want: 0,
},
{
name: "in sync - right after bootstrap",
time: genesis.Add(time.Duration(bootstrapEpoch+1) * period),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch + 1), period: period},
want: 0,
},
{
name: "in sync - right before bootstrap (offset)",
time: genesis.Add(time.Duration(bootstrapEpoch-1)*period + 15*time.Second),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch - 1), period: period},
want: 15 * time.Second,
},
{
name: "in sync - right after bootstrap (offset)",
time: genesis.Add(time.Duration(bootstrapEpoch)*period + 1*time.Second),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch), period: period},
want: 0 * time.Second,
},
{
name: "out of sync - way after bootstrap",
time: genesis.Add(time.Duration(bootstrapEpoch+100)*period + 1*time.Second),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch - 100), period: period},
want: 1 * time.Nanosecond, // we don't start immediately as the tipset we need is not available yet
},
{
name: "out of sync - way before bootstrap",
time: genesis.Add(time.Duration(bootstrapEpoch-30)*period + 1*time.Second),
ts: tipset{genesis: genesis, epoch: int64(bootstrapEpoch - 100), period: period},
want: 30*period - 1*time.Second,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
clock.Set(tc.time)
got := computeBootstrapDelay(&tc.ts, clock, m)
if got != tc.want {
t.Errorf("computeBootstrapDelay(%s, %v, %v) = %v, want %v", &tc.ts, tc.time, period, got, tc.want)
}
})
}
}