-
Notifications
You must be signed in to change notification settings - Fork 0
/
inflight_test.go
62 lines (51 loc) · 1.02 KB
/
inflight_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
package yaft
import (
"fmt"
"testing"
)
func TestInflight_StartCommit(t *testing.T) {
commitCh := make(chan *DeferLog, 1)
in := NewInflight(commitCh)
// Commit a transaction as being in flight
l := &DeferLog{
log: Log{Index: 1},
DeferError: DeferError{errCh: make(chan error)},
}
in.Start(l, 3)
// Commit 3 times
in.Commit(1)
select {
case <-commitCh:
t.Fatalf("should not be commited")
default:
}
in.Commit(1)
select {
case <-commitCh:
t.Fatalf("should not be commited")
default:
}
in.Commit(1)
select {
case <-commitCh:
default:
t.Fatalf("should be commited")
}
}
func TestInflight_Cancel(t *testing.T) {
commitCh := make(chan *DeferLog, 1)
in := NewInflight(commitCh)
// Commit a transaction as being in flight
l := &DeferLog{
log: Log{Index: 1},
DeferError: DeferError{errCh: make(chan error)},
}
in.Start(l, 3)
// Cancel with an error
err := fmt.Errorf("error 1")
in.Cancel(err)
// Should get an error return
if l.Error() != err {
t.Fatalf("expected error")
}
}