satellite/accounting: test that project limit cache is really used
We just fixed case were project limit cache was not used properly. This is test case to cover that fix. Change-Id: Iee467f0a46836860a14ab6238a9842ffbf54ed4c
This commit is contained in:
parent
38c7671acb
commit
e181f4b90e
@ -6,6 +6,7 @@ package accounting_test
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -185,5 +186,31 @@ func TestProjectLimitCache(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, expectedSegmentLimit, *actualSegmentLimitFromDB)
|
||||
})
|
||||
|
||||
t.Run("cache is used", func(t *testing.T) {
|
||||
require.NoError(t, accountingDB.UpdateProjectUsageLimit(ctx, testProject.ID, 1))
|
||||
require.NoError(t, accountingDB.UpdateProjectBandwidthLimit(ctx, testProject.ID, 2))
|
||||
require.NoError(t, accountingDB.UpdateProjectSegmentLimit(ctx, testProject.ID, 3))
|
||||
|
||||
projectLimitCache := accounting.NewProjectLimitCache(accountingDB, 0, 0, 0, accounting.ProjectLimitConfig{
|
||||
CacheCapacity: 10,
|
||||
CacheExpiration: 60 * time.Second,
|
||||
})
|
||||
|
||||
// fill cache with values from DB
|
||||
beforeCachedLimits, err := projectLimitCache.GetLimits(ctx, testProject.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// update limits in DB but not in cache
|
||||
require.NoError(t, accountingDB.UpdateProjectUsageLimit(ctx, testProject.ID, 4))
|
||||
require.NoError(t, accountingDB.UpdateProjectBandwidthLimit(ctx, testProject.ID, 5))
|
||||
require.NoError(t, accountingDB.UpdateProjectSegmentLimit(ctx, testProject.ID, 6))
|
||||
|
||||
// verify that old values are still cached because expiration time was not reached yet
|
||||
afterCachedLimits, err := projectLimitCache.GetLimits(ctx, testProject.ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, beforeCachedLimits, afterCachedLimits)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user