From 2e912b88231e675a01051c981022c068b7f26c2c Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Thu, 18 Feb 2021 11:38:27 -0800 Subject: [PATCH] Fixed tests for changes in RoundEventCallback --- api/messages_test.go | 49 ++++++++++++++++++++++++++++--------- api/utilsInterfaces_test.go | 21 ---------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/api/messages_test.go b/api/messages_test.go index c4e85d129..54433f2e9 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 be3000b56..6eb4c466a 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{} -- GitLab