Skip to content
Snippets Groups Projects
Commit 4e83be61 authored by Josh Brooks's avatar Josh Brooks
Browse files

Improve testing code

parent 96c6ee14
Branches
Tags
1 merge request!58Revert "Modify waiting lock"
......@@ -100,7 +100,7 @@ func TestRoundEvents_TriggerRoundEvent(t *testing.T) {
State: uint32(states.PENDING),
}
if err := testutils.SignRoundInfo(ri); err != nil {
if err := testutils.SignRoundInfo(ri, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
......@@ -139,7 +139,7 @@ func TestRoundEvents_AddRoundEventChan(t *testing.T) {
ID: uint64(rid),
State: uint32(states.PENDING),
}
if err := testutils.SignRoundInfo(ri); err != nil {
if err := testutils.SignRoundInfo(ri, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
......
......@@ -35,7 +35,7 @@ func TestUpdates_GetUpdate(t *testing.T) {
ID: 0,
UpdateID: uint64(updateID),
}
if err := testutils.SignRoundInfo(ri); err != nil {
if err := testutils.SignRoundInfo(ri, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
rnd := NewRound(ri, testutils.LoadKeyTesting(t))
......@@ -54,7 +54,7 @@ func TestUpdates_GetUpdates(t *testing.T) {
ID: 0,
UpdateID: uint64(updateID),
}
if err := testutils.SignRoundInfo(roundInfoOne); err != nil {
if err := testutils.SignRoundInfo(roundInfoOne, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
roundOne := NewRound(roundInfoOne, testutils.LoadKeyTesting(t))
......@@ -64,7 +64,7 @@ func TestUpdates_GetUpdates(t *testing.T) {
ID: 0,
UpdateID: uint64(updateID + 1),
}
if err := testutils.SignRoundInfo(roundInfoTwo); err != nil {
if err := testutils.SignRoundInfo(roundInfoTwo, t); err != nil {
t.Errorf("Failed to sign mock round info: %v", err)
}
roundTwo := NewRound(roundInfoTwo, testutils.LoadKeyTesting(t))
......
......@@ -37,7 +37,7 @@ func TestNewRound_Get(t *testing.T) {
pubKey := testutils.LoadKeyTesting(t)
ri := &mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)}
// Mock signature of roundInfo as it will be verified in codepath
testutils.SignRoundInfo(ri)
testutils.SignRoundInfo(ri, t)
rnd := NewRound(ri, pubKey)
// Check the initial value of the atomic value (lazily)
......
......@@ -159,7 +159,7 @@ func TestWaitingRounds_GetUpcomingRealtime_NoWait(t *testing.T) {
testWR := NewWaitingRounds()
for _, round := range testRounds {
testutils.SignRoundInfo(round.info)
testutils.SignRoundInfo(round.info, t)
testWR.Insert(round)
}
......@@ -202,7 +202,7 @@ func TestWaitingRounds_GetUpcomingRealtime(t *testing.T) {
for i, round := range expectedRounds {
go func(round *Round) {
time.Sleep(30 * time.Millisecond)
testutils.SignRoundInfo(round.info)
testutils.SignRoundInfo(round.info, t)
testWR.Insert(round)
}(round)
......@@ -232,7 +232,7 @@ func TestWaitingRounds_GetSlice(t *testing.T) {
Timestamps: []uint64{0, 0, 0, 0, 0},
}
testutils.SignRoundInfo(ri)
testutils.SignRoundInfo(ri, t)
rnd := NewRound(ri, testutils.LoadKeyTesting(t))
......
......@@ -166,7 +166,7 @@ func TestInstance_GetRoundUpdate(t *testing.T) {
}
ri := &mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)}
testutils.SignRoundInfo(ri)
testutils.SignRoundInfo(ri, t)
rnd := ds.NewRound(ri, testutils.LoadKeyTesting(t))
_ = i.roundUpdates.AddRound(rnd)
......@@ -182,9 +182,9 @@ func TestInstance_GetRoundUpdates(t *testing.T) {
}
roundInfoOne := &mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(1)}
testutils.SignRoundInfo(roundInfoOne)
testutils.SignRoundInfo(roundInfoOne, t)
roundInfoTwo := &mixmessages.RoundInfo{ID: uint64(1), UpdateID: uint64(2)}
testutils.SignRoundInfo(roundInfoTwo)
testutils.SignRoundInfo(roundInfoTwo, t)
roundOne := ds.NewRound(roundInfoOne, testutils.LoadKeyTesting(t))
roundTwo := ds.NewRound(roundInfoTwo, testutils.LoadKeyTesting(t))
......
......@@ -35,7 +35,18 @@ func LoadKeyTesting(t *testing.T) *rsa.PublicKey {
}
// Utility function which signs a round info message
func SignRoundInfo(ri *pb.RoundInfo) error {
func SignRoundInfo(ri *pb.RoundInfo, i interface{}) error {
switch i.(type) {
case *testing.T:
break
case *testing.M:
break
case *testing.B:
break
default:
jww.FATAL.Panicf("SignRoundInfo is restricted to testing only. Got %T", i)
}
keyPath := testkeys.GetNodeKeyPath()
keyData := testkeys.LoadFromPath(keyPath)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment