-
Notifications
You must be signed in to change notification settings - Fork 379
test: integrate synctest in access control pkg #5296
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
base: master
Are you sure you want to change the base?
Conversation
c243af3 to
1a8e92d
Compare
test and scope CI tests to pk…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.
Pull request overview
This PR integrates synctest from the testing/synctest package into the access control test suite to enable deterministic time-based testing. The change wraps a test case that involves time-dependent behavior (adding and revoking access with historical timestamp lookups) in a synctest.Test wrapper.
Key Changes
- Added
testing/synctestimport to the test file - Wrapped the "add and revoke then get from history" test case with
synctest.Test()for controlled time advancement
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| time.Sleep(1 * time.Second) | ||
| beforeRevokeTS := time.Now().Unix() | ||
| _, egranteeRef, hrefUpdate1, _, err := c.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, hRef, &publisher.PublicKey, addRevokeList, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| time.Sleep(1 * time.Second) |
Copilot
AI
Dec 1, 2025
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.
When using synctest.Test, you should replace time.Sleep() calls with synctest.Wait() to properly utilize synctest's controlled time advancement. The current implementation wraps the test with synctest but still uses time.Sleep(), which defeats the purpose of using synctest.
Replace:
time.Sleep(1 * time.Second)With:
synctest.Wait()This pattern is used consistently in other parts of the codebase (e.g., pkg/blocker/blocker_test.go).
| time.Sleep(1 * time.Second) | |
| beforeRevokeTS := time.Now().Unix() | |
| _, egranteeRef, hrefUpdate1, _, err := c.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, hRef, &publisher.PublicKey, addRevokeList, nil) | |
| require.NoError(t, err) | |
| time.Sleep(1 * time.Second) | |
| synctest.Wait() | |
| beforeRevokeTS := time.Now().Unix() | |
| _, egranteeRef, hrefUpdate1, _, err := c.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, hRef, &publisher.PublicKey, addRevokeList, nil) | |
| require.NoError(t, err) | |
| synctest.Wait() |
| time.Sleep(1 * time.Second) | ||
| beforeRevokeTS := time.Now().Unix() | ||
| _, egranteeRef, hrefUpdate1, _, err := c.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, hRef, &publisher.PublicKey, addRevokeList, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| time.Sleep(1 * time.Second) |
Copilot
AI
Dec 1, 2025
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.
When using synctest.Test, you should replace time.Sleep() calls with synctest.Wait() to properly utilize synctest's controlled time advancement. The current implementation wraps the test with synctest but still uses time.Sleep(), which defeats the purpose of using synctest.
Replace:
time.Sleep(1 * time.Second)With:
synctest.Wait()This pattern is used consistently in other parts of the codebase (e.g., pkg/blocker/blocker_test.go).
| time.Sleep(1 * time.Second) | |
| beforeRevokeTS := time.Now().Unix() | |
| _, egranteeRef, hrefUpdate1, _, err := c.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, hRef, &publisher.PublicKey, addRevokeList, nil) | |
| require.NoError(t, err) | |
| time.Sleep(1 * time.Second) | |
| synctest.Wait() | |
| beforeRevokeTS := time.Now().Unix() | |
| _, egranteeRef, hrefUpdate1, _, err := c.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, hRef, &publisher.PublicKey, addRevokeList, nil) | |
| require.NoError(t, err) | |
| synctest.Wait() |
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.
synctest.Wait() doesn't advance time, it only waits until all goroutines are blocked according to the official docs.
This test needs the virtual clock to actually advance so i kept the time.Sleep(). The comment on line 245 explains why.
So without time.Sleep() in this test, time.Now() returns the same value twice, causing an error.
Checklist
Description
Add
synctestincontroller_test.goOpen API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
#5232
Screenshots (if appropriate):