storagenode/console: consoleAPI EstimatedPayout flacky test fixed
In rare cases time frame between creating time.Now() variable and calling service method that receives it (after API method call) was big enough to distort current month expectations and make test fail with last digit difference in 1 Change-Id: Ib811492d62f6598a5c40a09de6a87bffeaa0a78e
This commit is contained in:
parent
d2f4ea1f24
commit
98b8c7be06
@ -69,11 +69,9 @@ func TestStorageNodeApi(t *testing.T) {
|
|||||||
reputationdb := sno.DB.Reputation()
|
reputationdb := sno.DB.Reputation()
|
||||||
baseURL := fmt.Sprintf("http://%s/api/sno", console.Listener.Addr())
|
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()
|
sno.NodeStats.Cache.Reputation.Pause()
|
||||||
|
startingPoint := time.Now().UTC().Add(-2 * time.Hour)
|
||||||
now := time.Now().UTC()
|
|
||||||
startingPoint := now.Add(-2 * time.Hour)
|
|
||||||
|
|
||||||
for _, action := range actions {
|
for _, action := range actions {
|
||||||
err := bandwidthdb.Add(ctx, satellite.ID(), action, 2300000000000, startingPoint)
|
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
|
// 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)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/estimated-payout", baseURL), nil)
|
||||||
require.NoError(t, err)
|
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)
|
res, err := http.DefaultClient.Do(req)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
@ -119,19 +121,19 @@ func TestStorageNodeApi(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, body)
|
||||||
|
|
||||||
bodyPayout := &estimatedpayouts.EstimatedPayout{}
|
bodyPayout := &estimatedpayouts.EstimatedPayout{}
|
||||||
require.NoError(t, json.Unmarshal(body, bodyPayout))
|
require.NoError(t, json.Unmarshal(body, bodyPayout))
|
||||||
|
|
||||||
estimation, err := sno.Console.Service.GetAllSatellitesEstimatedPayout(ctx, now)
|
estimation, err := sno.Console.Service.GetAllSatellitesEstimatedPayout(ctx, now)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expectedPayout := &estimatedpayouts.EstimatedPayout{
|
expectedPayout := &estimatedpayouts.EstimatedPayout{
|
||||||
CurrentMonth: estimation.CurrentMonth,
|
CurrentMonth: estimation.CurrentMonth,
|
||||||
PreviousMonth: estimation.PreviousMonth,
|
PreviousMonth: estimation.PreviousMonth,
|
||||||
CurrentMonthExpectations: estimation.CurrentMonthExpectations,
|
CurrentMonthExpectations: estimation.CurrentMonthExpectations,
|
||||||
}
|
}
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
require.EqualValues(t, expectedPayout, bodyPayout)
|
require.EqualValues(t, expectedPayout, bodyPayout)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user