From aa49c8c44d24b5157302573e2199f329947d4e28 Mon Sep 17 00:00:00 2001 From: Fadila Khadar Date: Tue, 1 Jun 2021 10:09:37 +0200 Subject: [PATCH] satellite/orders: fix TestProjectUsageBandwidth Change-Id: I3e9e81ea1ac2b0d7ef0936e4480a6b13c36bfcc5 --- satellite/accounting/projectusage_test.go | 3 +++ satellite/satellitedb/projectaccounting.go | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/satellite/accounting/projectusage_test.go b/satellite/accounting/projectusage_test.go index f98308bba..fda864052 100644 --- a/satellite/accounting/projectusage_test.go +++ b/satellite/accounting/projectusage_test.go @@ -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) diff --git a/satellite/satellitedb/projectaccounting.go b/satellite/satellitedb/projectaccounting.go index d7a095c94..ad4477e1a 100644 --- a/satellite/satellitedb/projectaccounting.go +++ b/satellite/satellitedb/projectaccounting.go @@ -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 {