diff --git a/storagenode/console/consoleapi/storagenode_test.go b/storagenode/console/consoleapi/storagenode_test.go index 5e52d425f..07c7a1487 100644 --- a/storagenode/console/consoleapi/storagenode_test.go +++ b/storagenode/console/consoleapi/storagenode_test.go @@ -69,11 +69,9 @@ func TestStorageNodeApi(t *testing.T) { reputationdb := sno.DB.Reputation() baseURL := fmt.Sprintf("http://%s/api/sno", console.Listener.Addr()) - // pause nodestats reputation cache because later tests assert a specific joinedat. + // pause node stats reputation cache because later tests assert a specific join date. sno.NodeStats.Cache.Reputation.Pause() - - now := time.Now().UTC() - startingPoint := now.Add(-2 * time.Hour) + startingPoint := time.Now().UTC().Add(-2 * time.Hour) for _, action := range actions { err := bandwidthdb.Add(ctx, satellite.ID(), action, 2300000000000, startingPoint) @@ -108,6 +106,10 @@ func TestStorageNodeApi(t *testing.T) { // should return estimated payout for both satellites in current month and empty for previous req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/estimated-payout", baseURL), nil) require.NoError(t, err) + + // setting now here to cache closest to api all timestamp, so service call + // would not have difference in passed "now" that can distort result + now := time.Now() res, err := http.DefaultClient.Do(req) require.NoError(t, err) require.NotNil(t, res) @@ -119,19 +121,19 @@ func TestStorageNodeApi(t *testing.T) { }() body, err := ioutil.ReadAll(res.Body) require.NoError(t, err) + require.NotNil(t, body) bodyPayout := &estimatedpayouts.EstimatedPayout{} require.NoError(t, json.Unmarshal(body, bodyPayout)) estimation, err := sno.Console.Service.GetAllSatellitesEstimatedPayout(ctx, now) require.NoError(t, err) + expectedPayout := &estimatedpayouts.EstimatedPayout{ CurrentMonth: estimation.CurrentMonth, PreviousMonth: estimation.PreviousMonth, CurrentMonthExpectations: estimation.CurrentMonthExpectations, } - require.NoError(t, err) - require.EqualValues(t, expectedPayout, bodyPayout) }) },