Commit de50aa52 authored by Thomas Hoffmann's avatar Thomas Hoffmann
Browse files

Merge

parent 39a00bb0
Pipeline #21390 passed with stages
in 1 minute and 1 second
......@@ -10,6 +10,8 @@ import (
"strconv"
"testing"
"time"
"github.com/google/uuid"
)
/////////////////////
......@@ -220,13 +222,13 @@ func setupElection() *Election {
RequiredServers: 2,
Deadline: time.Now().Add(1 * time.Minute),
CloseCallback: func(reason Reason) {},
TallyCallback: func() {},
TallyCallback: func(tally *Tally) {},
ResultCallback: func(result *Result) {},
}
return NewElection(config)
}
func testCloseCondition(t *testing.T, expectedReason Reason, expectedPhase Phase, fun func(*Election)) {
func testCloseCondition(t *testing.T, expectedReason Reason, expectedPhase Phase, fun func(*Election)) *Election {
log.SetOutput(ioutil.Discard)
close := make(chan bool, 1)
timeout := make(chan bool, 1)
......@@ -258,21 +260,26 @@ func testCloseCondition(t *testing.T, expectedReason Reason, expectedPhase Phase
if e.Status.Phase != expectedPhase {
t.Errorf("Unexpected phase\n Expected: %s\n Actual: %s\n", expectedPhase, e.Status.Phase)
}
return e
}
func TestCloseDeadline(t *testing.T) {
testCloseCondition(t, ReasonDeadline, PhaseClosed, func(e *Election) {})
_ = testCloseCondition(t, ReasonDeadline, PhaseClosed, func(e *Election) {})
}
func TestCloseAgreement(t *testing.T) {
testCloseCondition(t, ReasonAgreement, PhaseTallying, func(e *Election) {
_ = testCloseCondition(t, ReasonAgreement, PhaseTallying, func(e *Election) {
ballots := CreateBallots(3, createXS(1), big.NewInt(1))
e.HandleBallot(UniqueID(strconv.Itoa(1)), ballots["1"])
e.HandleClosing("2")
e.HandleClosing("3")
})
}
func TestCloseAllVotes(t *testing.T) {
testCloseCondition(t, ReasonVotes, PhaseClosed, func(e *Election) {
_ = testCloseCondition(t, ReasonVotes, PhaseClosed, func(e *Election) {
for i := 1; i <= e.Participants.Voters; i++ {
ballots := CreateBallots(3, createXS(1), big.NewInt(1))
e.HandleBallot(UniqueID(strconv.Itoa(i)), ballots["1"])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment