satellite/orders: fix TestProjectUsageBandwidth

Change-Id: I3e9e81ea1ac2b0d7ef0936e4480a6b13c36bfcc5
This commit is contained in:
Fadila Khadar 2021-06-01 10:09:37 +02:00
parent 91b7e24d55
commit aa49c8c44d
2 changed files with 6 additions and 3 deletions

View File

@ -146,6 +146,9 @@ func TestProjectUsageBandwidth(t *testing.T) {
err = planet.Uplinks[0].Upload(ctx, planet.Satellites[0], bucket.BucketName, filePath, expectedData)
require.NoError(t, err)
projectUsage.SetNow(func() time.Time {
return now
})
actualExceeded, _, err := projectUsage.ExceedsBandwidthUsage(ctx, bucket.ProjectID)
require.NoError(t, err)
require.Equal(t, testCase.expectedExceeded, actualExceeded)

View File

@ -150,16 +150,16 @@ func (db *ProjectAccounting) GetProjectBandwidth(ctx context.Context, projectID
} else {
expiredSince = time.Date(year, month, day-allocatedExpirationInDays+1, 0, 0, 0, 0, time.UTC)
}
periodEnd := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
periodEnd := time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC)
query := ` WITH egress AS (
SELECT
CASE WHEN interval_day < ?
CASE WHEN interval_day <= ?
THEN egress_settled
ELSE egress_allocated
END AS amount
FROM project_bandwidth_daily_rollups
WHERE project_id = ? AND interval_day >= ? AND interval_day <= ?
WHERE project_id = ? AND interval_day >= ? AND interval_day < ?
) SELECT sum(amount) from egress;`
err = db.db.QueryRow(ctx, db.db.Rebind(query), expiredSince, projectID[:], startOfMonth, periodEnd).Scan(&egress)
if errors.Is(err, sql.ErrNoRows) || egress == nil {