diff --git a/api/messages_test.go b/api/messages_test.go index c4e85d1297f1e0b55090dd1ee9b9353550b24bec..54433f2e9b8bcfd91e3d83e5745bdc1d3ceecc75 100644 --- a/api/messages_test.go +++ b/api/messages_test.go @@ -43,8 +43,14 @@ func TestClient_GetRoundResults(t *testing.T) { t.Errorf("Failed in setup: %v", err) } + // Construct the round call back function signature + var successfulRounds, timeout bool + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) { + successfulRounds = allRoundsSucceeded + timeout = timedOut + } + // Call the round results - receivedRCB := NewMockRoundCB() err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, receivedRCB, sendResults, NewNoHistoricalRoundsComm()) if err != nil { @@ -55,11 +61,11 @@ func TestClient_GetRoundResults(t *testing.T) { time.Sleep(1 * time.Second) // If any rounds timed out or any round failed, the happy path has failed - if receivedRCB.timedOut || !receivedRCB.allRoundsSucceeded { + if timeout || !successfulRounds { t.Errorf("Unexpected round failures in happy path. "+ "Expected all rounds to succeed with no timeouts."+ "\n\tTimedOut: %v"+ - "\n\tallRoundsSucceeded: %v", receivedRCB.timedOut, receivedRCB.allRoundsSucceeded) + "\n\tallRoundsSucceeded: %v", timeout, successfulRounds) } } @@ -100,8 +106,14 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) { t.Errorf("Failed in setup: %v", err) } + // Construct the round call back function signature + var successfulRounds, timeout bool + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) { + successfulRounds = allRoundsSucceeded + timeout = timedOut + } + // Call the round results - receivedRCB := NewMockRoundCB() err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, receivedRCB, sendResults, NewNoHistoricalRoundsComm()) if err != nil { @@ -112,10 +124,10 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) { time.Sleep(2 * time.Second) // If no rounds have failed, this test has failed - if receivedRCB.allRoundsSucceeded { + if successfulRounds { t.Errorf("Expected some rounds to fail. "+ "\n\tTimedOut: %v"+ - "\n\tallRoundsSucceeded: %v", receivedRCB.timedOut, receivedRCB.allRoundsSucceeded) + "\n\tallRoundsSucceeded: %v", timeout, successfulRounds) } } @@ -166,8 +178,14 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) { } + // Construct the round call back function signature + var successfulRounds, timeout bool + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) { + successfulRounds = allRoundsSucceeded + timeout = timedOut + } + // Call the round results - receivedRCB := NewMockRoundCB() err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, receivedRCB, sendResults, NewHistoricalRoundsComm()) if err != nil { @@ -178,10 +196,10 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) { time.Sleep(2 * time.Second) // If no round failed, this test has failed - if receivedRCB.allRoundsSucceeded { + if successfulRounds { t.Errorf("Expected historical rounds to have round failures"+ "\n\tTimedOut: %v"+ - "\n\tallRoundsSucceeded: %v", receivedRCB.timedOut, receivedRCB.allRoundsSucceeded) + "\n\tallRoundsSucceeded: %v", timeout, successfulRounds) } } @@ -204,8 +222,14 @@ func TestClient_GetRoundResults_Timeout(t *testing.T) { t.Errorf("Failed in setup: %v", err) } + // Construct the round call back function signature + var successfulRounds, timeout bool + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) { + successfulRounds = allRoundsSucceeded + timeout = timedOut + } + // Call the round results - receivedRCB := NewMockRoundCB() err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, receivedRCB, sendResults, NewNoHistoricalRoundsComm()) if err != nil { @@ -216,9 +240,10 @@ func TestClient_GetRoundResults_Timeout(t *testing.T) { time.Sleep(2 * time.Second) // If no rounds have timed out , this test has failed - if !receivedRCB.timedOut { + if !timeout { t.Errorf("Expected all rounds to timeout with no valid round reporter."+ - "\n\tTimedOut: %v", receivedRCB.timedOut) + "\n\tTimedOut: %v"+ + "\n\tallRoundsSucceeded: %v", timeout, successfulRounds) } } diff --git a/api/utilsInterfaces_test.go b/api/utilsInterfaces_test.go index be3000b56a253c1873c52b924cac8e6551cce812..6eb4c466a51845e756f275483271a785b643feaa 100644 --- a/api/utilsInterfaces_test.go +++ b/api/utilsInterfaces_test.go @@ -21,27 +21,6 @@ import ( "gitlab.com/xx_network/primitives/id/ephemeral" ) -// A mock structure which should conform to the callback for getRoundResults -type mockRoundCallback struct { - allRoundsSucceeded bool - timedOut bool - rounds map[id.Round]RoundResult -} - -// Construction for mockRoundCallback -func NewMockRoundCB() *mockRoundCallback { - return &mockRoundCallback{} -} - -// Report simply stores the passed in values in the structure -func (mrc *mockRoundCallback) Report(allRoundsSucceeded, timedOut bool, - rounds map[id.Round]RoundResult) { - - mrc.allRoundsSucceeded = allRoundsSucceeded - mrc.timedOut = timedOut - mrc.rounds = rounds -} - // Mock comm struct which returns no historical round data type noHistoricalRounds struct{}