storagenode/console: estimated payout tests fix
Added check if days paste <1 and node joined in current month -> days paste = 1 Change-Id: Ice1ccd6c869f629a87da585850b9b4f3729ec65c
This commit is contained in:
parent
27bcb46718
commit
866a3e3ad3
@ -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)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user