storagenode:consoleAPI flacky tests for estimatedPayout fixed

joinedAt date now is 2 months before time.Now which should fix calculations on early dates.

Change-Id: I6250ec2463c2dd609e811b74d908a02a3e64f19a
This commit is contained in:
Qweder93 2021-03-10 19:20:55 +02:00
parent dcdfa10370
commit 487ad84b23
2 changed files with 4 additions and 8 deletions

View File

@ -18,7 +18,6 @@ import (
"storj.io/common/pb" "storj.io/common/pb"
"storj.io/common/storj" "storj.io/common/storj"
"storj.io/common/testcontext" "storj.io/common/testcontext"
"storj.io/storj/private/date"
"storj.io/storj/private/testplanet" "storj.io/storj/private/testplanet"
"storj.io/storj/satellite" "storj.io/storj/satellite"
"storj.io/storj/storagenode/payouts/estimatedpayouts" "storj.io/storj/storagenode/payouts/estimatedpayouts"
@ -96,12 +95,9 @@ func TestStorageNodeApi(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
now2 := time.Now().UTC()
daysPerMonth := date.UTCEndOfMonth(now2).Day()
err = reputationdb.Store(ctx, reputation.Stats{ err = reputationdb.Store(ctx, reputation.Stats{
SatelliteID: satellite.ID(), SatelliteID: satellite.ID(),
JoinedAt: now.AddDate(0, 0, -daysPerMonth+3), JoinedAt: now.AddDate(0, -2, 0),
}) })
require.NoError(t, err) require.NoError(t, err)
@ -134,8 +130,8 @@ func TestStorageNodeApi(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// round CurrentMonthExpectations to 3 decimal places to resolve precision issues // round CurrentMonthExpectations to 3 decimal places to resolve precision issues
bodyPayout.CurrentMonthExpectations = math.Floor(bodyPayout.CurrentMonthExpectations*1000) / 1000 bodyPayout.CurrentMonthExpectations = math.Round(bodyPayout.CurrentMonthExpectations*100) / 100
expectedPayout.CurrentMonthExpectations = math.Floor(expectedPayout.CurrentMonthExpectations*1000) / 1000 expectedPayout.CurrentMonthExpectations = math.Round(expectedPayout.CurrentMonthExpectations*100) / 100
require.EqualValues(t, expectedPayout, bodyPayout) require.EqualValues(t, expectedPayout, bodyPayout)
}) })

View File

@ -97,7 +97,7 @@ func (estimatedPayout *EstimatedPayout) Set(current, previous PayoutMonthly, now
return return
} }
estimatedPayout.CurrentMonthExpectations += estimatedPayout.CurrentMonth.Payout / daysSinceJoined * daysPerMonth estimatedPayout.CurrentMonthExpectations += estimatedPayout.CurrentMonth.Payout / math.Round(daysSinceJoined) * daysPerMonth
} }
// Add adds estimate into the receiver. // Add adds estimate into the receiver.