-
Notifications
You must be signed in to change notification settings - Fork 244
fix(test): wait for prefetch to complete before file verification #1815
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?
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -328,7 +328,16 @@ func (nydusd *Nydusd) Mount() error { | |||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return nydusd.WaitStatus("RUNNING") | ||||||||||||||||||||||||||
| err = nydusd.WaitStatus("RUNNING") | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if nydusd.EnablePrefetch { | ||||||||||||||||||||||||||
| nydusd.waitPrefetch() | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func (nydusd *Nydusd) MountByAPI(config NydusdConfig) error { | ||||||||||||||||||||||||||
|
|
@@ -361,8 +370,15 @@ func (nydusd *Nydusd) MountByAPI(config NydusdConfig) error { | |||||||||||||||||||||||||
| "application/json", | ||||||||||||||||||||||||||
| bytes.NewBuffer(body), | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||
| if config.EnablePrefetch { | ||||||||||||||||||||||||||
| nydusd.waitPrefetch() | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func (nydusd *Nydusd) Umount() error { | ||||||||||||||||||||||||||
|
|
@@ -696,3 +712,34 @@ func Verify(t *testing.T, ctx Context, expectedFileTree map[string]*File) { | |||||||||||||||||||||||||
| defer nydusd.Umount() | ||||||||||||||||||||||||||
| nydusd.Verify(t, expectedFileTree) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func (nydusd *Nydusd) waitPrefetch() { | ||||||||||||||||||||||||||
| // Wait for prefetch to start and stabilize | ||||||||||||||||||||||||||
| deadline := time.Now().Add(10 * time.Second) | ||||||||||||||||||||||||||
| var lastReadCount uint64 | ||||||||||||||||||||||||||
| stableCount := 0 | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for time.Now().Before(deadline) { | ||||||||||||||||||||||||||
| time.Sleep(500 * time.Millisecond) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| metrics, err := nydusd.GetBackendMetrics() | ||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if metrics.ReadCount == 0 { | ||||||||||||||||||||||||||
|
Comment on lines
+729
to
+730
|
||||||||||||||||||||||||||
| if metrics.ReadCount == 0 { | |
| // If there is no prefetch data configured or needed, return early instead of | |
| // waiting for ReadCount to change. | |
| if metrics.ReadCount == 0 { | |
| // PrefetchDataAmount comes from BlobCacheMetrics; 0 here means there is | |
| // nothing to prefetch (e.g., empty filesystem or everything already cached). | |
| if metrics.PrefetchDataAmount == 0 { | |
| return | |
| } | |
| // There is prefetch work, but it hasn't started generating reads yet. |
Copilot
AI
Dec 23, 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.
The timeout duration of 10 seconds, polling interval of 500 milliseconds, and stability threshold of 3 consecutive identical reads are hardcoded. These values may not be appropriate for all environments (e.g., slower CI systems, larger prefetch operations). Consider making these configurable through environment variables or the NydusdConfig structure to allow tuning for different test scenarios and environments.
Copilot
AI
Dec 23, 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.
The waitPrefetch method silently returns without any indication of success or failure. When the deadline expires without achieving stable read counts, the function returns normally, which could lead to false positives in tests where prefetch actually failed or timed out. Consider adding logging to distinguish between successful completion and timeout scenarios, or returning an error when the timeout is reached. This would make test failures more debuggable and help identify when the timeout duration needs adjustment.
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.
Errors from GetBackendMetrics are silently ignored with continue statements. While this approach ensures the wait loop doesn't fail prematurely, it could mask underlying issues such as the API being unavailable, authentication problems, or other persistent errors. Consider adding logging for these errors or implementing a counter to fail fast if consecutive errors exceed a threshold, helping identify configuration or connectivity issues earlier.