MCPcopy
hub / github.com/seaweedfs/seaweedfs / waitForFileContent

Function waitForFileContent

test/fuse_integration/writeback_cache_test.go:38–55  ·  view source on GitHub ↗

waitForFileContent polls until a file has the expected content or timeout expires. This is needed because writebackCache defers data upload to background goroutines, so there is a brief window after close() where the file may not yet be readable.

(t *testing.T, path string, expected []byte, timeout time.Duration)

Source from the content-addressed store, hash-verified

36// This is needed because writebackCache defers data upload to background goroutines,
37// so there is a brief window after close() where the file may not yet be readable.
38func waitForFileContent(t *testing.T, path string, expected []byte, timeout time.Duration) {
39 t.Helper()
40 deadline := time.Now().Add(timeout)
41 var lastErr error
42 for time.Now().Before(deadline) {
43 actual, err := os.ReadFile(path)
44 if err == nil && bytes.Equal(expected, actual) {
45 return
46 }
47 if err != nil {
48 lastErr = err
49 } else {
50 lastErr = fmt.Errorf("content mismatch: got %d bytes, want %d bytes", len(actual), len(expected))
51 }
52 time.Sleep(200 * time.Millisecond)
53 }
54 t.Fatalf("file %s did not have expected content within %v: %v", path, timeout, lastErr)
55}
56
57// waitForFileSize polls until a file reports the expected size or timeout expires.
58func waitForFileSize(t *testing.T, path string, expectedSize int64, timeout time.Duration) {

Calls 3

NowMethod · 0.80
ReadFileMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected