-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to disable synchronization on creation for auto refresh cache #5940
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,40 @@ func TestCacheFour(t *testing.T) { | |
assert.NoError(t, err) | ||
} | ||
|
||
// Cache should be processing | ||
assert.NotEmpty(t, cache.processing) | ||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding initial state validation
Consider adding assertions to verify the initial state of cache items before triggering the sync. This would help validate that items are properly initialized with Code suggestionCheck the AI-generated fix before applying
Code Review Run #8a272a Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||
|
||
assert.EventuallyWithT(t, func(c *assert.CollectT) { | ||
// trigger periodic sync | ||
fakeClock.Step(testResyncPeriod) | ||
|
||
for i := 1; i <= 10; i++ { | ||
item, err := cache.Get(fmt.Sprintf("%d", i)) | ||
assert.NoError(c, err) | ||
assert.Equal(c, 10, item.(fakeCacheItem).val) | ||
} | ||
}, 3*time.Second, time.Millisecond) | ||
cancel() | ||
}) | ||
|
||
t.Run("disable sync on create", func(t *testing.T) { | ||
cache, err := NewInMemoryAutoRefresh("fake1", syncFakeItem, rateLimiter, testResyncPeriod, 10, 10, promutils.NewTestScope(), WithClock(fakeClock), WithSyncOnCreate(false)) | ||
assert.NoError(t, err) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
assert.NoError(t, cache.Start(ctx)) | ||
|
||
// Create ten items in the cache | ||
for i := 1; i <= 10; i++ { | ||
_, err := cache.GetOrCreate(fmt.Sprintf("%d", i), fakeCacheItem{ | ||
val: 0, | ||
}) | ||
assert.NoError(t, err) | ||
} | ||
|
||
// Validate that none are processing since they aren't synced on creation | ||
assert.Empty(t, cache.processing) | ||
|
||
assert.EventuallyWithT(t, func(c *assert.CollectT) { | ||
// trigger periodic sync | ||
fakeClock.Step(testResyncPeriod) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check for
w.workqueue
being nil before using it inGetOrCreate
. Theworkqueue
field could potentially be nil if initialization failed.Code suggestion
Code Review Run #8a272a
Is this a valid issue, or was it incorrectly flagged by the Agent?