Skip to content

Commit 146dff0

Browse files
committed
Fixes a wrong check in the integration test
1 parent 5777176 commit 146dff0

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
4545
golang.org/x/text v0.3.7 // indirect
4646
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
47-
google.golang.org/grpc v1.45.0 // indirect
48-
google.golang.org/protobuf v1.26.0 // indirect
47+
google.golang.org/grpc v1.49.0 // indirect
48+
google.golang.org/protobuf v1.27.1 // indirect
4949
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
5050
)

go.sum

+5-3
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
124124
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
125125
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
126126
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
127-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
128127
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
128+
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
129129
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
130130
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
131131
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -534,8 +534,9 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
534534
google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
535535
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
536536
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
537-
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
538537
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
538+
google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw=
539+
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
539540
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
540541
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
541542
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -547,8 +548,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
547548
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
548549
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
549550
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
550-
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
551551
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
552+
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
553+
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
552554
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
553555
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
554556
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

integration/integration_test.go

+32-19
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
110110
err = closeElection(m, electionID, adminID)
111111
require.NoError(t, err)
112112

113-
waitForStatus(t, types.Closed, electionFac, electionID, nodes, numNodes,
113+
err = waitForStatus(types.Closed, electionFac, electionID, nodes, numNodes,
114114
5*time.Second)
115+
require.NoError(t, err)
115116

116117
// ##### SHUFFLE BALLOTS #####
117118
t.Logf("initializing shuffle")
@@ -124,8 +125,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
124125
err = sActor.Shuffle(electionID)
125126
require.NoError(t, err)
126127

127-
waitForStatus(t, types.ShuffledBallots, electionFac, electionID, nodes,
128+
err = waitForStatus(types.ShuffledBallots, electionFac, electionID, nodes,
128129
numNodes, 2*time.Second*time.Duration(numNodes))
130+
require.NoError(t, err)
129131

130132
// ##### SUBMIT PUBLIC SHARES #####
131133
t.Logf("submitting public shares")
@@ -135,8 +137,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
135137
err = actor.ComputePubshares()
136138
require.NoError(t, err)
137139

138-
waitForStatus(t, types.PubSharesSubmitted, electionFac, electionID, nodes,
140+
err = waitForStatus(types.PubSharesSubmitted, electionFac, electionID, nodes,
139141
numNodes, 6*time.Second*time.Duration(numNodes))
142+
require.NoError(t, err)
140143

141144
// ##### DECRYPT BALLOTS #####
142145
t.Logf("decrypting")
@@ -147,8 +150,9 @@ func getIntegrationTest(numNodes, numVotes int) func(*testing.T) {
147150
err = decryptBallots(m, actor, election)
148151
require.NoError(t, err)
149152

150-
waitForStatus(t, types.ResultAvailable, electionFac, electionID, nodes,
153+
err = waitForStatus(types.ResultAvailable, electionFac, electionID, nodes,
151154
numNodes, 1500*time.Millisecond*time.Duration(numVotes))
155+
require.NoError(t, err)
152156

153157
t.Logf("get vote proof")
154158
election, err = getElection(electionFac, electionID, nodes[0].GetOrdering())
@@ -576,31 +580,40 @@ func encodeID(ID string) types.ID {
576580

577581
// waitForStatus polls the nodes until they all updated to the expected status
578582
// 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)
587587

588-
isOK := func() bool {
588+
isOK := func() (bool, error) {
589589
for _, node := range nodes {
590590
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+
}
592594

593595
if election.Status != status {
594-
return false
596+
return false, nil
595597
}
596598
}
597599

598-
return true
600+
return true, nil
599601
}
600602

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+
602617
time.Sleep(time.Millisecond * 100)
603618
}
604-
605-
timer.Stop()
606619
}

0 commit comments

Comments
 (0)