99 "testing"
1010 "time"
1111
12- "google.golang.org/grpc"
13-
1412 "code.cloudfoundry.org/clock/fakeclock"
13+ "github.com/docker/go-events"
1514 "github.com/moby/swarmkit/v2/api"
1615 "github.com/moby/swarmkit/v2/ca"
1716 cautils "github.com/moby/swarmkit/v2/ca/testutils"
@@ -25,6 +24,7 @@ import (
2524 "github.com/stretchr/testify/require"
2625 etcdraft "go.etcd.io/etcd/raft/v3"
2726 "go.etcd.io/etcd/raft/v3/raftpb"
27+ "google.golang.org/grpc"
2828)
2929
3030// TestNode represents a raft test node
@@ -46,6 +46,38 @@ func (n *TestNode) Leader() uint64 {
4646 return id
4747}
4848
49+ func (n * TestNode ) Status () etcdraft.Status {
50+ return n .Node .Status ()
51+ }
52+
53+ func (n * TestNode ) Run (ctx context.Context ) {
54+ n .Node .Run (ctx )
55+ }
56+
57+ func (n * TestNode ) Done () <- chan struct {} {
58+ return n .Node .Done ()
59+ }
60+
61+ func (n * TestNode ) ProposeValue (ctx context.Context , actions []api.StoreAction , cb func ()) error {
62+ return n .Node .ProposeValue (ctx , actions , cb )
63+ }
64+
65+ func (n * TestNode ) MemoryStore () * store.MemoryStore {
66+ return n .Node .MemoryStore ()
67+ }
68+
69+ func (n * TestNode ) ReadyForProposals () bool {
70+ return n .Node .ReadyForProposals ()
71+ }
72+
73+ func (n * TestNode ) GetMemberlist () map [uint64 ]* api.RaftMember {
74+ return n .Node .GetMemberlist ()
75+ }
76+
77+ func (n * TestNode ) SubscribeLeadership () (q chan events.Event , cancel func ()) {
78+ return n .Node .SubscribeLeadership ()
79+ }
80+
4981// AdvanceTicks advances the raft state machine fake clock
5082func AdvanceTicks (clockSource * fakeclock.FakeClock , ticks int ) {
5183 // A FakeClock timer won't fire multiple times if time is advanced
@@ -66,7 +98,7 @@ func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[ui
6698 prev = new (etcdraft.Status )
6799 * prev = n .Status ()
68100 for _ , n2 := range nodes {
69- if n2 .Config .ID == prev .Lead {
101+ if n2 .Node . Config .ID == prev .Lead {
70102 leadNode = n2
71103 continue nodeLoop
72104 }
@@ -76,7 +108,7 @@ func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[ui
76108 cur := n .Status ()
77109
78110 for _ , n2 := range nodes {
79- if n2 .Config .ID == cur .Lead {
111+ if n2 .Node . Config .ID == cur .Lead {
80112 if cur .Lead != prev .Lead || cur .Term != prev .Term || cur .Applied != prev .Applied {
81113 return errors .New ("state does not match on all nodes" )
82114 }
@@ -496,7 +528,7 @@ func CleanupNonRunningNode(node *TestNode) {
496528// belonging to the same cluster
497529func Leader (nodes map [uint64 ]* TestNode ) * TestNode {
498530 for _ , n := range nodes {
499- if n .Config .ID == n .Leader () {
531+ if n .Node . Config .ID == n .Leader () {
500532 return n
501533 }
502534 }
0 commit comments