forked from hashicorp/raft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inflight_test.go
63 lines (52 loc) · 1.05 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
63
package raft
import (
"fmt"
"testing"
)
func TestInflight_StartCommit(t *testing.T) {
commitCh := make(chan *logFuture, 1)
in := newInflight(commitCh)
// Commit a transaction as being in flight
l := &logFuture{log: Log{Index: 1}}
l.policy = newMajorityQuorum(5)
in.Start(l)
// Commit 3 times
in.Commit(1, nil)
select {
case <-commitCh:
t.Fatalf("should not be commited")
default:
}
in.Commit(1, nil)
select {
case <-commitCh:
t.Fatalf("should not be commited")
default:
}
in.Commit(1, nil)
select {
case <-commitCh:
default:
t.Fatalf("should be commited")
}
// Already commited but should work anyways
in.Commit(1, nil)
}
func TestInflight_Cancel(t *testing.T) {
commitCh := make(chan *logFuture, 1)
in := newInflight(commitCh)
// Commit a transaction as being in flight
l := &logFuture{
log: Log{Index: 1},
}
l.init()
l.policy = newMajorityQuorum(3)
in.Start(l)
// 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")
}
}