From 866a3e3ad37a4df4a37c278a6e130f460c6fa2c9 Mon Sep 17 00:00:00 2001 From: Qweder93 Date: Tue, 23 Mar 2021 17:39:02 +0200 Subject: [PATCH] storagenode/console: estimated payout tests fix Added check if days paste <1 and node joined in current month -> days paste = 1 Change-Id: Ice1ccd6c869f629a87da585850b9b4f3729ec65c --- .../console/consoleapi/storagenode_test.go | 16 +++++++++------- .../payouts/estimatedpayouts/estimatedpayouts.go | 6 ++++-- storagenode/payouts/estimatedpayouts/service.go | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/storagenode/console/consoleapi/storagenode_test.go b/storagenode/console/consoleapi/storagenode_test.go index 7359756bd..9ad9b9b56 100644 --- a/storagenode/console/consoleapi/storagenode_test.go +++ b/storagenode/console/consoleapi/storagenode_test.go @@ -70,6 +70,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. + sno.NodeStats.Cache.Reputation.Pause() + now := time.Now().UTC().Add(-2 * time.Hour) for _, action := range actions { @@ -84,6 +87,12 @@ func TestStorageNodeApi(t *testing.T) { err := storageusagedb.Store(ctx, stamps) require.NoError(t, err) + err = reputationdb.Store(ctx, reputation.Stats{ + SatelliteID: satellite.ID(), + JoinedAt: now.AddDate(0, -2, 0), + }) + require.NoError(t, err) + egressPrice, repairPrice, auditPrice, diskPrice := int64(2000), int64(1000), int64(1000), int64(150) err = pricingdb.Store(ctx, pricing.Pricing{ @@ -95,14 +104,7 @@ func TestStorageNodeApi(t *testing.T) { }) require.NoError(t, err) - err = reputationdb.Store(ctx, reputation.Stats{ - SatelliteID: satellite.ID(), - JoinedAt: now.AddDate(0, -2, 0), - }) - require.NoError(t, err) - t.Run("test EstimatedPayout", func(t *testing.T) { - t.Skip("disabled until flakiness fixed") // should return estimated payout for both satellites in current month and empty for previous url := fmt.Sprintf("%s/estimated-payout", baseURL) diff --git a/storagenode/payouts/estimatedpayouts/estimatedpayouts.go b/storagenode/payouts/estimatedpayouts/estimatedpayouts.go index f312febfc..dde01fba6 100644 --- a/storagenode/payouts/estimatedpayouts/estimatedpayouts.go +++ b/storagenode/payouts/estimatedpayouts/estimatedpayouts.go @@ -82,8 +82,11 @@ func (estimatedPayout *EstimatedPayout) Set(current, previous PayoutMonthly, now estimatedPayout.CurrentMonth = current estimatedPayout.PreviousMonth = previous - daysSinceJoined := now.Sub(joinedAt).Hours() / 24 daysPerMonth := float64(date.UTCEndOfMonth(now).Day()) + daysSinceJoined := now.Sub(joinedAt).Hours() / 24 + if daysSinceJoined < 1 { + daysSinceJoined = 1 + } if daysSinceJoined >= float64(now.Day()) { daysPast := float64(now.Day()) - 1 @@ -92,7 +95,6 @@ func (estimatedPayout *EstimatedPayout) Set(current, previous PayoutMonthly, now } payoutPerDay := estimatedPayout.CurrentMonth.Payout / daysPast - estimatedPayout.CurrentMonthExpectations += payoutPerDay * daysPerMonth return } diff --git a/storagenode/payouts/estimatedpayouts/service.go b/storagenode/payouts/estimatedpayouts/service.go index dc710a835..72565dbc8 100644 --- a/storagenode/payouts/estimatedpayouts/service.go +++ b/storagenode/payouts/estimatedpayouts/service.go @@ -80,7 +80,6 @@ func (s *Service) GetAllSatellitesEstimatedPayout(ctx context.Context, now time. if err != nil { return EstimatedPayout{}, EstimationServiceErr.Wrap(err) } - var satellitePayout EstimatedPayout stats, err := s.reputationDB.Get(ctx, satelliteIDs[i]) @@ -108,7 +107,6 @@ func (s *Service) estimatedPayout(ctx context.Context, satelliteID storj.NodeID, if err != nil { return PayoutMonthly{}, PayoutMonthly{}, EstimationServiceErr.Wrap(err) } - currentMonthPayout, err = s.estimationUsagePeriod(ctx, now.UTC(), stats.JoinedAt, priceModel) previousMonthPayout, err = s.estimationUsagePeriod(ctx, now.UTC().AddDate(0, -1, 0), stats.JoinedAt, priceModel)