Repository navigation
test(data): wait for shapefile change time before checking a rewrite #3621
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
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -971,12 +971,32 @@ fn a_shapefile_says_whether_it_is_as_it_was_opened() { | |||||||
| cache::with_index_dir(tmp.path().join("cache"), || { | ||||||||
| let s = ShpSource::open_path(&path, "pts").unwrap(); | ||||||||
| assert!(s.same_as_opened().unwrap(), "as opened"); | ||||||||
| // The same size, its time set back: the change time still moves. | ||||||||
| // The same size, its time set back: the change time still moves. It moves with the | ||||||||
| // system's coarse clock, so a write in the tick the file was opened in leaves it as it | ||||||||
| // was: written again until it has moved (a few milliseconds). | ||||||||
| let dbf = path.with_extension("dbf"); | ||||||||
| let modified = std::fs::metadata(&dbf).unwrap().modified().unwrap(); | ||||||||
| let bytes = std::fs::read(&dbf).unwrap(); | ||||||||
| std::fs::write(&dbf, &bytes).unwrap(); | ||||||||
| std::fs::File::options().write(true).open(&dbf).unwrap().set_modified(modified).unwrap(); | ||||||||
| #[cfg(unix)] | ||||||||
| let changed_at = |p: &std::path::Path| { | ||||||||
| use std::os::unix::fs::MetadataExt; | ||||||||
| let m = std::fs::metadata(p).unwrap(); | ||||||||
| (m.ctime(), m.ctime_nsec()) | ||||||||
| }; | ||||||||
| #[cfg(unix)] | ||||||||
| let opened_at = changed_at(&dbf); | ||||||||
| let rewrite = || { | ||||||||
| std::fs::write(&dbf, &bytes).unwrap(); | ||||||||
| std::fs::File::options().write(true).open(&dbf).unwrap().set_modified(modified).unwrap(); | ||||||||
| }; | ||||||||
| rewrite(); | ||||||||
| #[cfg(unix)] | ||||||||
| { | ||||||||
| let give_up = std::time::Instant::now() + std::time::Duration::from_secs(2); // test-wait: the change time moves with the system's clock tick, which no signal announces; two seconds cover a file system that keeps whole seconds. | ||||||||
| while changed_at(&dbf) == opened_at && std::time::Instant::now() < give_up { | ||||||||
| rewrite(); | ||||||||
| } | ||||||||
| } | ||||||||
|
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. If the two-second deadline passes with the change time unmoved, the test falls through to
Suggested change
Category: quality
Member
Author
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. A clearer message for a timed-out wait is left for the release quality pass. |
||||||||
| #[cfg(unix)] | ||||||||
| assert!(!s.same_as_opened().unwrap(), "written again at the same size and time"); | ||||||||
| let s = ShpSource::open_path(&path, "pts").unwrap(); | ||||||||
|
|
||||||||
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.
On non-Unix targets the loop body always ends in
break, so thefornever loops more than once. That should trip clippy'snever_looplint (deny by default) on Windows and other non-Unix runs, even though Linux CI passes. Moving the write into a closure and putting the loop only under#[cfg(unix)]keeps the same behaviour and removes the dead-loop shape:Category: quality
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.
Right: fixed in 041f262. The rewrite loop is now Unix-only; other systems write the file once.