@@ -43,7 +43,7 @@ var serdecontext = json.NewContext()
43
43
44
44
// Check the shuffled votes versus the cast votes on a few nodes
45
45
func TestIntegration (t * testing.T ) {
46
- t .Run ("3 nodes, 3 votes" , getIntegrationTest (3 , 3 ))
46
+ // t.Run("3 nodes, 3 votes", getIntegrationTest(3, 3))
47
47
t .Run ("10 nodes, 10 votes" , getIntegrationTest (10 , 10 ))
48
48
}
49
49
@@ -110,8 +110,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
110
110
err = closeElection (m , electionID , adminID )
111
111
require .NoError (t , err )
112
112
113
- waitForStatus (t , types .Closed , electionFac , electionID , nodes , numNodes ,
113
+ err = waitForStatus (types .Closed , electionFac , electionID , nodes , numNodes ,
114
114
5 * time .Second )
115
+ require .NoError (t , err )
115
116
116
117
// ##### SHUFFLE BALLOTS #####
117
118
t .Logf ("initializing shuffle" )
@@ -124,8 +125,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
124
125
err = sActor .Shuffle (electionID )
125
126
require .NoError (t , err )
126
127
127
- waitForStatus (t , types .ShuffledBallots , electionFac , electionID , nodes ,
128
+ err = waitForStatus (types .ShuffledBallots , electionFac , electionID , nodes ,
128
129
numNodes , 2 * time .Second * time .Duration (numNodes ))
130
+ require .NoError (t , err )
129
131
130
132
// ##### SUBMIT PUBLIC SHARES #####
131
133
t .Logf ("submitting public shares" )
@@ -135,8 +137,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
135
137
err = actor .ComputePubshares ()
136
138
require .NoError (t , err )
137
139
138
- waitForStatus (t , types .PubSharesSubmitted , electionFac , electionID , nodes ,
140
+ err = waitForStatus (types .PubSharesSubmitted , electionFac , electionID , nodes ,
139
141
numNodes , 6 * time .Second * time .Duration (numNodes ))
142
+ require .NoError (t , err )
140
143
141
144
// ##### DECRYPT BALLOTS #####
142
145
t .Logf ("decrypting" )
@@ -147,8 +150,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
147
150
err = decryptBallots (m , actor , election )
148
151
require .NoError (t , err )
149
152
150
- waitForStatus (t , types .ResultAvailable , electionFac , electionID , nodes ,
153
+ err = waitForStatus (types .ResultAvailable , electionFac , electionID , nodes ,
151
154
numNodes , 1500 * time .Millisecond * time .Duration (numVotes ))
155
+ require .NoError (t , err )
152
156
153
157
t .Logf ("get vote proof" )
154
158
election , err = getElection (electionFac , electionID , nodes [0 ].GetOrdering ())
@@ -576,31 +580,40 @@ func encodeID(ID string) types.ID {
576
580
577
581
// waitForStatus polls the nodes until they all updated to the expected status
578
582
// for the given election. An error is raised if the timeout expires.
579
- func waitForStatus (t * testing.T , status types.Status , electionFac types.ElectionFactory ,
580
- electionID []byte , nodes []dVotingCosiDela , numNodes int , timeOut time.Duration ) {
581
- // set up a timer to fail the test in case we never reach the status
582
- timer := time .NewTimer (timeOut )
583
- go func () {
584
- <- timer .C
585
- t .Errorf ("timed out while waiting for status %d" , status )
586
- }()
583
+ func waitForStatus (status types.Status , electionFac types.ElectionFactory ,
584
+ electionID []byte , nodes []dVotingCosiDela , numNodes int , timeOut time.Duration ) error {
585
+
586
+ expiration := time .Now ().Add (timeOut )
587
587
588
- isOK := func () bool {
588
+ isOK := func () ( bool , error ) {
589
589
for _ , node := range nodes {
590
590
election , err := getElection (electionFac , electionID , node .GetOrdering ())
591
- require .NoError (t , err )
591
+ if err != nil {
592
+ return false , xerrors .Errorf ("failed to get election: %v" , err )
593
+ }
592
594
593
595
if election .Status != status {
594
- return false
596
+ return false , nil
595
597
}
596
598
}
597
599
598
- return true
600
+ return true , nil
599
601
}
600
602
601
- for ! isOK () {
603
+ for {
604
+ if time .Now ().After (expiration ) {
605
+ return xerrors .New ("status check expired" )
606
+ }
607
+
608
+ ok , err := isOK ()
609
+ if err != nil {
610
+ return xerrors .Errorf ("failed to check status: %v" , err )
611
+ }
612
+
613
+ if ok {
614
+ return nil
615
+ }
616
+
602
617
time .Sleep (time .Millisecond * 100 )
603
618
}
604
-
605
- timer .Stop ()
606
619
}
0 commit comments