-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix flaky FileIOTest.testMatchWatchForNewFiles test under CI filesystems #38047
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -249,16 +249,25 @@ public void processElement(ProcessContext context, @StateId("count") ValueState< | |||||||||||||||||||
| context.output(Objects.requireNonNull(context.element()).getValue()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| CopyOption[] cpOptions = {StandardCopyOption.COPY_ATTRIBUTES}; | ||||||||||||||||||||
| CopyOption[] updOptions = {StandardCopyOption.REPLACE_EXISTING}; | ||||||||||||||||||||
| CopyOption[] updOptions = { | ||||||||||||||||||||
| StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| final Path sourcePath = Paths.get(sourcePathStr); | ||||||||||||||||||||
| final Path watchPath = Paths.get(watchPathStr); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (0 == current) { | ||||||||||||||||||||
| Thread.sleep(100); | ||||||||||||||||||||
| // Ensure overwrite updates get a distinct mtime even when COPY_ATTRIBUTES is enabled. | ||||||||||||||||||||
| Files.setLastModifiedTime( | ||||||||||||||||||||
| sourcePath.resolve("first"), FileTime.fromMillis(System.currentTimeMillis() + 2000)); | ||||||||||||||||||||
| Files.copy(sourcePath.resolve("first"), watchPath.resolve("first"), updOptions); | ||||||||||||||||||||
| Files.copy(sourcePath.resolve("second"), watchPath.resolve("second"), cpOptions); | ||||||||||||||||||||
| } else if (1 == current) { | ||||||||||||||||||||
| Thread.sleep(100); | ||||||||||||||||||||
| Files.setLastModifiedTime( | ||||||||||||||||||||
| sourcePath.resolve("first"), FileTime.fromMillis(System.currentTimeMillis() + 4000)); | ||||||||||||||||||||
| Files.setLastModifiedTime( | ||||||||||||||||||||
| sourcePath.resolve("second"), FileTime.fromMillis(System.currentTimeMillis() + 4000)); | ||||||||||||||||||||
|
Comment on lines
+267
to
+270
Contributor
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. Calling
Suggested change
|
||||||||||||||||||||
| Files.copy(sourcePath.resolve("first"), watchPath.resolve("first"), updOptions); | ||||||||||||||||||||
| Files.copy(sourcePath.resolve("second"), watchPath.resolve("second"), updOptions); | ||||||||||||||||||||
| Files.copy(sourcePath.resolve("third"), watchPath.resolve("third"), cpOptions); | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
Using a future timestamp (
System.currentTimeMillis() + 2000) is a workaround for filesystem resolution issues but can be fragile in environments that validate file timestamps. Consider if a more deterministic way to ensure increasing timestamps (e.g., using a base time and incrementing) would be more reliable.