From c0c0333b0263a6bd55337c0cc0bf15efd29b0e70 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Thu, 31 Mar 2022 11:13:08 -0700 Subject: [PATCH] added getroundresults to network package --- bindings/client.go | 5 +- cmd/root.go | 3 +- cmd/utils.go | 8 +- e2e/interface.go | 2 +- fileTransfer/manager.go | 3 +- fileTransfer/oldTransferRecovery_test.go | 20 +-- fileTransfer/send.go | 7 +- fileTransfer/send_test.go | 8 +- fileTransfer/utils_test.go | 10 +- network/interface.go | 9 +- {api => network}/results.go | 168 ++++++++++++----------- {api => network}/results_test.go | 35 ++--- 12 files changed, 145 insertions(+), 133 deletions(-) rename {api => network}/results.go (64%) rename {api => network}/results_test.go (89%) diff --git a/bindings/client.go b/bindings/client.go index f0f74433f..2068bfbfa 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -13,6 +13,7 @@ import ( "encoding/json" "errors" "fmt" + "gitlab.com/elixxir/client/network" "runtime/pprof" "strings" "sync" @@ -407,7 +408,7 @@ func (c *Client) RegisterRoundEventsHandler(rid int, cb RoundEventCallback, func (c *Client) WaitForRoundCompletion(roundID int, rec RoundCompletionCallback, timeoutMS int) error { - f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult) { + f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]network.RoundLookupStatus) { rec.EventCallback(roundID, allRoundsSucceeded, timedOut) } @@ -442,7 +443,7 @@ func (c *Client) WaitForMessageDelivery(marshaledSendReport []byte, "unmarshal: %s", string(marshaledSendReport))) } - f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult) { + f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]network.RoundLookupStatus) { results := make([]byte, len(sr.rl.list)) jww.INFO.Printf("Processing WaitForMessageDelivery report "+ "for %v, success: %v, timedout: %v", sr.mid, allRoundsSucceeded, diff --git a/cmd/root.go b/cmd/root.go index c34ab06cc..39f8ee6bd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,6 +14,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "gitlab.com/elixxir/client/network" "io/ioutil" "log" "os" @@ -377,7 +378,7 @@ var rootCmd = &cobra.Command{ // Construct the callback function which // verifies successful message send or retries f := func(allRoundsSucceeded, timedOut bool, - rounds map[id.Round]api.RoundResult) { + rounds map[id.Round]network.RoundLookupStatus) { printRoundResults(allRoundsSucceeded, timedOut, rounds, roundIDs, msg) if !allRoundsSucceeded { retryChan <- struct{}{} diff --git a/cmd/utils.go b/cmd/utils.go index 9e26e2c76..5ded04095 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -4,8 +4,8 @@ import ( "fmt" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/viper" - "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/network" backupCrypto "gitlab.com/elixxir/crypto/backup" "gitlab.com/elixxir/crypto/contact" "gitlab.com/xx_network/primitives/id" @@ -47,7 +47,7 @@ func printChanRequest(requestor contact.Contact) { // Helper function which prints the round resuls func printRoundResults(allRoundsSucceeded, timedOut bool, - rounds map[id.Round]api.RoundResult, roundIDs []id.Round, msg message.Send) { + rounds map[id.Round]network.RoundLookupStatus, roundIDs []id.Round, msg message.Send) { // Done as string slices for easy and human readable printing successfulRounds := make([]string, 0) @@ -58,9 +58,9 @@ func printRoundResults(allRoundsSucceeded, timedOut bool, // Group all round reports into a category based on their // result (successful, failed, or timed out) if result, exists := rounds[r]; exists { - if result == api.Succeeded { + if result == network.Succeeded { successfulRounds = append(successfulRounds, strconv.Itoa(int(r))) - } else if result == api.Failed { + } else if result == network.Failed { failedRounds = append(failedRounds, strconv.Itoa(int(r))) } else { timedOutRounds = append(timedOutRounds, strconv.Itoa(int(r))) diff --git a/e2e/interface.go b/e2e/interface.go index ecbaf75be..d9990b4d4 100644 --- a/e2e/interface.go +++ b/e2e/interface.go @@ -96,7 +96,7 @@ type Handler interface { // sessions using the passed cryptographic data and per the parameters sent AddPartner(partnerID *id.ID, partnerPubKey, myPrivKey *cyclic.Int, partnerSIDHPubKey *sidh.PublicKey, mySIDHPrivKey *sidh.PrivateKey, - sendParams, receiveParams session.Params) (*partner.Manager, error) + sendParams, receiveParams session.Params, myID *id.ID, myPrivateKey *cyclic.Int, temporary bool) (*partner.Manager, error) // GetPartner returns the partner per its ID, if it exists GetPartner(partnerID *id.ID) (*partner.Manager, error) diff --git a/fileTransfer/manager.go b/fileTransfer/manager.go index 713e230c9..7fc8e3416 100644 --- a/fileTransfer/manager.go +++ b/fileTransfer/manager.go @@ -13,6 +13,7 @@ import ( "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/network" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" ftStorage "gitlab.com/elixxir/client/storage/fileTransfer" @@ -119,7 +120,7 @@ type Manager struct { // getRoundResultsFunc is a function that matches client.GetRoundResults. It is // used to pass in an alternative function for testing. type getRoundResultsFunc func(roundList []id.Round, timeout time.Duration, - roundCallback api.RoundEventCallback) error + roundCallback network.RoundEventCallback) error // queuedPart contains the unique information identifying a file part. type queuedPart struct { diff --git a/fileTransfer/oldTransferRecovery_test.go b/fileTransfer/oldTransferRecovery_test.go index 341b39542..561785100 100644 --- a/fileTransfer/oldTransferRecovery_test.go +++ b/fileTransfer/oldTransferRecovery_test.go @@ -10,8 +10,8 @@ package fileTransfer import ( "fmt" "github.com/pkg/errors" - "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/network" "gitlab.com/elixxir/client/storage/versioned" ftCrypto "gitlab.com/elixxir/crypto/fileTransfer" "gitlab.com/elixxir/ekv" @@ -77,13 +77,13 @@ func TestManager_oldTransferRecovery(t *testing.T) { // Returns an error on function and round failure on callback if sendErr is // set; otherwise, it reports round successes and returns nil - rr := func(rIDs []id.Round, _ time.Duration, cb api.RoundEventCallback) error { - rounds := make(map[id.Round]api.RoundResult, len(rIDs)) + rr := func(rIDs []id.Round, _ time.Duration, cb network.RoundEventCallback) error { + rounds := make(map[id.Round]network.RoundLookupStatus, len(rIDs)) for _, rid := range rIDs { if finishedRounds[rid] != nil { - rounds[rid] = api.Succeeded + rounds[rid] = network.Succeeded } else { - rounds[rid] = api.Failed + rounds[rid] = network.Failed } } cb(true, false, rounds) @@ -240,13 +240,13 @@ func TestManager_updateSentRounds(t *testing.T) { // Returns an error on function and round failure on callback if sendErr is // set; otherwise, it reports round successes and returns nil - rr := func(rIDs []id.Round, _ time.Duration, cb api.RoundEventCallback) error { - rounds := make(map[id.Round]api.RoundResult, len(rIDs)) + rr := func(rIDs []id.Round, _ time.Duration, cb network.RoundEventCallback) error { + rounds := make(map[id.Round]network.RoundLookupStatus, len(rIDs)) for _, rid := range rIDs { if finishedRounds[rid] != nil { - rounds[rid] = api.Succeeded + rounds[rid] = network.Succeeded } else { - rounds[rid] = api.Failed + rounds[rid] = network.Failed } } cb(true, false, rounds) @@ -322,7 +322,7 @@ func TestManager_updateSentRounds_Error(t *testing.T) { // Returns an error on function and round failure on callback if sendErr is // set; otherwise, it reports round successes and returns nil m.getRoundResults = func( - []id.Round, time.Duration, api.RoundEventCallback) error { + []id.Round, time.Duration, network.RoundEventCallback) error { return errors.Errorf("GetRoundResults error") } diff --git a/fileTransfer/send.go b/fileTransfer/send.go index fb593445f..299db3b0e 100644 --- a/fileTransfer/send.go +++ b/fileTransfer/send.go @@ -12,7 +12,6 @@ import ( "encoding/binary" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/network" @@ -419,11 +418,11 @@ func (m *Manager) newCmixMessage(transfer *ftStorage.SentTransfer, // fails, then each part for each transfer is removed from the in-progress list, // added to the end of the sending queue, and the callback called with an error. func (m *Manager) makeRoundEventCallback( - sentRounds map[id.Round][]ftCrypto.TransferID) api.RoundEventCallback { + sentRounds map[id.Round][]ftCrypto.TransferID) network.RoundEventCallback { - return func(allSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult) { + return func(allSucceeded, timedOut bool, rounds map[id.Round]network.RoundLookupStatus) { for rid, roundResult := range rounds { - if roundResult == api.Succeeded { + if roundResult == network.Succeeded { // If the round succeeded, then set all parts for each transfer // for this round to finished and call the progress callback for _, tid := range sentRounds[rid] { diff --git a/fileTransfer/send_test.go b/fileTransfer/send_test.go index d090d4dca..35e1f239a 100644 --- a/fileTransfer/send_test.go +++ b/fileTransfer/send_test.go @@ -12,10 +12,10 @@ import ( "errors" "fmt" "github.com/cloudflare/circl/dh/sidh" - "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/network" "gitlab.com/elixxir/client/stoppable" ftStorage "gitlab.com/elixxir/client/storage/fileTransfer" util "gitlab.com/elixxir/client/storage/utility" @@ -382,7 +382,7 @@ func TestManager_sendParts_RoundResultsError(t *testing.T) { grrErr := errors.New("GetRoundResultsError") m.getRoundResults = - func([]id.Round, time.Duration, api.RoundEventCallback) error { + func([]id.Round, time.Duration, network.RoundEventCallback) error { return grrErr } @@ -765,7 +765,7 @@ func TestManager_makeRoundEventCallback(t *testing.T) { roundEventCB := m.makeRoundEventCallback( map[id.Round][]ftCrypto.TransferID{rid: {tid}}) - roundEventCB(true, false, map[id.Round]api.RoundResult{rid: api.Succeeded}) + roundEventCB(true, false, map[id.Round]network.RoundLookupStatus{rid: network.Succeeded}) <-done1 @@ -853,7 +853,7 @@ func TestManager_makeRoundEventCallback_RoundFailure(t *testing.T) { roundEventCB := m.makeRoundEventCallback( map[id.Round][]ftCrypto.TransferID{rid: {tid}}) - roundEventCB(false, false, map[id.Round]api.RoundResult{rid: api.Failed}) + roundEventCB(false, false, map[id.Round]network.RoundLookupStatus{rid: network.Failed}) <-done1 diff --git a/fileTransfer/utils_test.go b/fileTransfer/utils_test.go index 6065e0441..0ea0e5386 100644 --- a/fileTransfer/utils_test.go +++ b/fileTransfer/utils_test.go @@ -12,11 +12,11 @@ import ( "encoding/binary" "github.com/cloudflare/circl/dh/sidh" "github.com/pkg/errors" - "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/event" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" + network2 "gitlab.com/elixxir/client/network" "gitlab.com/elixxir/client/network/gateway" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" @@ -170,13 +170,13 @@ func newTestManager(sendErr bool, sendChan, sendE2eChan chan message.Receive, // Returns an error on function and round failure on callback if sendErr is // set; otherwise, it reports round successes and returns nil - rr := func(rIDs []id.Round, _ time.Duration, cb api.RoundEventCallback) error { - rounds := make(map[id.Round]api.RoundResult, len(rIDs)) + rr := func(rIDs []id.Round, _ time.Duration, cb network2.RoundEventCallback) error { + rounds := make(map[id.Round]network2.RoundLookupStatus, len(rIDs)) for _, rid := range rIDs { if sendErr { - rounds[rid] = api.Failed + rounds[rid] = network2.Failed } else { - rounds[rid] = api.Succeeded + rounds[rid] = network2.Succeeded } } cb(!sendErr, false, rounds) diff --git a/network/interface.go b/network/interface.go index fa047f5ed..665ba791d 100644 --- a/network/interface.go +++ b/network/interface.go @@ -150,7 +150,7 @@ type Manager interface { // A service may have a nil response unless it is default. In general a // nil service is used to detect notifications when pickup is done by // fingerprints - AddService(AddService *id.ID, newService message.Service, + AddService(clientID *id.ID, newService message.Service, response message.Processor) // DeleteService deletes a message service. If only a single response is @@ -214,12 +214,17 @@ type Manager interface { // with a given node. TriggerNodeRegistration(nid *id.ID) - /* === Historical Rounds ================================================ */ + /* === Rounds =========================================================== */ /* A complete set of round info is not kept on the client, and sometimes the network will need to be queried to get round info. Historical rounds is the system internal to the Network Manager to do this. It can be used externally as well. */ + // GetRoundResults adjudicates on the rounds requested. Checks if they are + // older rounds or in progress rounds. + GetRoundResults(roundList []id.Round, timeout time.Duration, + roundCallback RoundEventCallback) error + // LookupHistoricalRound looks up the passed historical round on the network. LookupHistoricalRound( rid id.Round, callback historical.RoundResultCallback) error diff --git a/api/results.go b/network/results.go similarity index 64% rename from api/results.go rename to network/results.go index eb0403dee..dbc16ae78 100644 --- a/api/results.go +++ b/network/results.go @@ -5,30 +5,29 @@ // LICENSE file // /////////////////////////////////////////////////////////////////////////////// -package api +package network import ( "fmt" + "gitlab.com/elixxir/client/network/historical" "time" jww "github.com/spf13/jwalterweatherman" - pb "gitlab.com/elixxir/comms/mixmessages" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/primitives/states" - "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" ) -// RoundResult is the enum of possible round results to pass back -type RoundResult uint +// RoundLookupStatus is the enum of possible round results to pass back +type RoundLookupStatus uint const ( - TimeOut RoundResult = iota + TimeOut RoundLookupStatus = iota Failed Succeeded ) -func (rr RoundResult) String() string { +func (rr RoundLookupStatus) String() string { switch rr { case TimeOut: return "TimeOut" @@ -41,6 +40,16 @@ func (rr RoundResult) String() string { } } +type RoundResult struct { + Status RoundLookupStatus + Round historical.Round +} + +type historicalRoundsRtn struct { + Success bool + Round historical.Round +} + // RoundEventCallback interface which reports the requested rounds. // Designed such that the caller may decide how much detail they need. // allRoundsSucceeded: @@ -53,41 +62,30 @@ func (rr RoundResult) String() string { // their respective round results type RoundEventCallback func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) -// Comm interface for RequestHistoricalRounds. -// Constructed for testability with getRoundResults -type historicalRoundsComm interface { - RequestHistoricalRounds(host *connect.Host, - message *pb.HistoricalRounds) (*pb.HistoricalRoundsResponse, error) - GetHost(hostId *id.ID) (*connect.Host, bool) -} - // GetRoundResults adjudicates on the rounds requested. Checks if they are // older rounds or in progress rounds. -func (c *Client) GetRoundResults(roundList []id.Round, timeout time.Duration, +func (m *manager) GetRoundResults(roundList []id.Round, timeout time.Duration, roundCallback RoundEventCallback) error { jww.INFO.Printf("GetRoundResults(%v, %s)", roundList, timeout) sendResults := make(chan ds.EventReturn, len(roundList)) - return c.getRoundResults(roundList, timeout, roundCallback, - sendResults, c.comms) + return m.getRoundResults(roundList, timeout, roundCallback, + sendResults) } // Helper function which does all the logic for GetRoundResults -func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, - roundCallback RoundEventCallback, sendResults chan ds.EventReturn, - commsInterface historicalRoundsComm) error { +func (m *manager) getRoundResults(roundList []id.Round, timeout time.Duration, + roundCallback RoundEventCallback, sendResults chan ds.EventReturn) error { - networkInstance := c.network.GetInstance() + networkInstance := m.GetInstance() // Generate a message to track all older rounds - historicalRequest := &pb.HistoricalRounds{ - Rounds: []uint64{}, - } + historicalRequest := make([]id.Round, 0, len(roundList)) // Generate all tracking structures for rounds - roundEvents := c.GetRoundEvents() + roundEvents := networkInstance.GetRoundEvents() roundsResults := make(map[id.Round]RoundResult) allRoundsSucceeded := true anyRoundTimedOut := false @@ -98,15 +96,23 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, // Parse and adjudicate every round for _, rnd := range roundList { // Every round is timed out by default, until proven to have finished - roundsResults[rnd] = TimeOut + roundsResults[rnd] = RoundResult{ + Status: TimeOut, + } roundInfo, err := networkInstance.GetRound(rnd) // If we have the round in the buffer if err == nil { // Check if the round is done (completed or failed) or in progress if states.Round(roundInfo.State) == states.COMPLETED { - roundsResults[rnd] = Succeeded + roundsResults[rnd] = RoundResult{ + Status: Succeeded, + Round: historical.MakeRound(roundInfo), + } } else if states.Round(roundInfo.State) == states.FAILED { - roundsResults[rnd] = Failed + roundsResults[rnd] = RoundResult{ + Status: Failed, + Round: historical.MakeRound(roundInfo), + } allRoundsSucceeded = false } else { // If in progress, add a channel monitoring its state @@ -119,7 +125,7 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, if rnd < oldestRound { // If round is older that oldest round in our buffer // Add it to the historical round request (performed later) - historicalRequest.Rounds = append(historicalRequest.Rounds, uint64(rnd)) + historicalRequest = append(historicalRequest, rnd) numResults++ } else { // Otherwise, monitor its progress @@ -129,10 +135,30 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, } } } - + historicalRoundsCh := make(chan RoundResult, len(historicalRequest)) // Find out what happened to old (historical) rounds if any are needed - if len(historicalRequest.Rounds) > 0 { - go c.getHistoricalRounds(historicalRequest, sendResults, commsInterface) + if len(historicalRequest) > 0 { + for _, rnd := range historicalRequest { + rrc := func(round historical.Round, success bool) { + var status RoundLookupStatus + if success { + status = Succeeded + } else { + status = TimeOut + } + historicalRoundsCh <- RoundResult{ + Status: status, + Round: round, + } + } + err := m.Retriever.LookupHistoricalRound(rnd, rrc) + if err != nil { + historicalRoundsCh <- RoundResult{ + Status: TimeOut, + } + } + } + } // Determine the results of all rounds requested @@ -147,11 +173,16 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, return } + var result RoundResult + hasResult := false + // Wait for info about rounds or the timeout to occur select { case <-timer.C: roundCallback(false, true, roundsResults) return + case result = <-historicalRoundsCh: + hasResult = true case roundReport := <-sendResults: numResults-- @@ -162,11 +193,18 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, roundInfo, err := networkInstance.GetRound(roundId) // If we have the round in the buffer if err == nil { + hasResult = true // Check if the round is done (completed or failed) or in progress if states.Round(roundInfo.State) == states.COMPLETED { - roundsResults[roundId] = Succeeded + result = RoundResult{ + Status: Succeeded, + Round: historical.MakeRound(roundInfo), + } } else if states.Round(roundInfo.State) == states.FAILED { - roundsResults[roundId] = Failed + result = RoundResult{ + Status: Failed, + Round: historical.MakeRound(roundInfo), + } allRoundsSucceeded = false } continue @@ -174,62 +212,28 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, allRoundsSucceeded = false anyRoundTimedOut = true } else { + hasResult = true // If available, denote the result if states.Round(roundReport.RoundInfo.State) == states.COMPLETED { - roundsResults[roundId] = Succeeded + result = RoundResult{ + Status: Succeeded, + Round: historical.MakeRound(roundReport.RoundInfo), + } } else { - roundsResults[roundId] = Failed + result = RoundResult{ + Status: Failed, + Round: historical.MakeRound(roundReport.RoundInfo), + } allRoundsSucceeded = false } } } + if hasResult { + roundsResults[result.Round.ID] = result + } + } }() return nil } - -// Helper function which asynchronously pings a random gateway until -// it gets information on its requested historical rounds -func (c *Client) getHistoricalRounds(msg *pb.HistoricalRounds, - sendResults chan ds.EventReturn, comms historicalRoundsComm) { - - var resp *pb.HistoricalRoundsResponse - - //retry 5 times - for i := 0; i < 5; i++ { - // Find a gateway to request about the roundRequests - result, err := c.GetNetworkInterface().GetSender().SendToAny(func(host *connect.Host) (interface{}, error) { - return comms.RequestHistoricalRounds(host, msg) - }, nil) - - // If an error, retry with (potentially) a different gw host. - // If no error from received gateway request, exit loop - // and process rounds - if err == nil { - resp = result.(*pb.HistoricalRoundsResponse) - break - } else { - jww.ERROR.Printf("Failed to lookup historical rounds: %s", err) - } - } - - if resp == nil { - return - } - - // Service historical rounds, sending back to the caller thread - for i, ri := range resp.Rounds { - if ri == nil { - // Handle unknown by historical rounds - sendResults <- ds.EventReturn{ - RoundInfo: &pb.RoundInfo{ID: msg.Rounds[i]}, - TimedOut: true, - } - } else { - sendResults <- ds.EventReturn{ - RoundInfo: ri, - } - } - } -} diff --git a/api/results_test.go b/network/results_test.go similarity index 89% rename from api/results_test.go rename to network/results_test.go index c5245dd9a..338d71f58 100644 --- a/api/results_test.go +++ b/network/results_test.go @@ -4,9 +4,10 @@ // Use of this source code is governed by a license that can be found in the // // LICENSE file // /////////////////////////////////////////////////////////////////////////////// -package api +package network import ( + "gitlab.com/elixxir/client/api" pb "gitlab.com/elixxir/comms/mixmessages" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/primitives/states" @@ -38,21 +39,21 @@ func TestClient_GetRoundResults(t *testing.T) { } // Create a new copy of the test client for this test - client, err := newTestingClient(t) + client, err := api.newTestingClient(t) if err != nil { t.Fatalf("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) { + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundLookupStatus) { successfulRounds = allRoundsSucceeded timeout = timedOut } // Call the round results err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, - receivedRCB, sendResults, NewNoHistoricalRoundsComm()) + receivedRCB, sendResults, api.NewNoHistoricalRoundsComm()) if err != nil { t.Errorf("Error in happy path: %v", err) } @@ -101,21 +102,21 @@ func TestClient_GetRoundResults_FailedRounds(t *testing.T) { } // Create a new copy of the test client for this test - client, err := newTestingClient(t) + client, err := api.newTestingClient(t) if err != nil { t.Fatalf("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) { + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundLookupStatus) { successfulRounds = allRoundsSucceeded timeout = timedOut } // Call the round results err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, - receivedRCB, sendResults, NewNoHistoricalRoundsComm()) + receivedRCB, sendResults, api.NewNoHistoricalRoundsComm()) if err != nil { t.Errorf("Error in happy path: %v", err) } @@ -144,8 +145,8 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) { sendResults := make(chan ds.EventReturn, len(roundList)-2) for i := 0; i < numRounds; i++ { // Skip sending rounds intended for historical rounds comm - if i == failedHistoricalRoundID || - i == completedHistoricalRoundID { + if i == api.failedHistoricalRoundID || + i == api.completedHistoricalRoundID { continue } @@ -159,15 +160,15 @@ func TestClient_GetRoundResults_HistoricalRounds(t *testing.T) { } // Create a new copy of the test client for this test - client, err := newTestingClient(t) + client, err := api.newTestingClient(t) if err != nil { t.Fatalf("Failed in setup: %v", err) } // Overpopulate the round buffer, ensuring a circle back of the ring buffer - for i := 1; i <= ds.RoundInfoBufLen+completedHistoricalRoundID+1; i++ { + for i := 1; i <= ds.RoundInfoBufLen+api.completedHistoricalRoundID+1; i++ { ri := &pb.RoundInfo{ID: uint64(i)} - if err = signRoundInfo(ri); err != nil { + if err = api.signRoundInfo(ri); err != nil { t.Errorf("Failed to sign round in set up: %v", err) } @@ -180,14 +181,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) { + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundLookupStatus) { successfulRounds = allRoundsSucceeded timeout = timedOut } // Call the round results err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, - receivedRCB, sendResults, NewHistoricalRoundsComm()) + receivedRCB, sendResults, api.NewHistoricalRoundsComm()) if err != nil { t.Errorf("Error in happy path: %v", err) } @@ -217,21 +218,21 @@ func TestClient_GetRoundResults_Timeout(t *testing.T) { sendResults = nil // Create a new copy of the test client for this test - client, err := newTestingClient(t) + client, err := api.newTestingClient(t) if err != nil { t.Fatalf("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) { + receivedRCB := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundLookupStatus) { successfulRounds = allRoundsSucceeded timeout = timedOut } // Call the round results err = client.getRoundResults(roundList, time.Duration(10)*time.Millisecond, - receivedRCB, sendResults, NewNoHistoricalRoundsComm()) + receivedRCB, sendResults, api.NewNoHistoricalRoundsComm()) if err != nil { t.Errorf("Error in happy path: %v", err) } -- GitLab