Skip to content

[Bug]: flaky test diskwatch::tests::a_queued_reload_that_is_refused_leaves_a_later_change_marked (the reload thread may look at the file after the test's next change) #1944

Closed

Description

@elpidioassinaturas

What happens

diskwatch::tests::a_queued_reload_that_is_refused_leaves_a_later_change_marked (crates/ui-egui/src/diskwatch.rs, added in #1804) sometimes fails at its second status check:

assertion `left == right` failed: the first reload started before the last change, the second never read
  left: Unchanged
 right: Changed

The failure isn't tied to a change. Seen so far:

Here it passed 40 of 40 runs alone and 6 of 6 runs of the whole rustgis-ui-egui lib suite. It failed only in a full cargo test --workspace, with other test binaries running at the same time. So it fails when the machine is busy.

Why

readjob::start spawns the reload's thread, and that thread looks at the file (diskwatch::observe) only once it runs, just before reading. The test then changes the file straight away:

app.run("ui.reloadData", json!({"layer": id})).unwrap();
replace(3);
app.run("ui.reloadData", json!({"layer": id})).unwrap();

If the thread starts after replace(3), the first reload looks at and reads the third version. It then acknowledges that version, so the status is Unchanged, and the test's premise ("the first reload started before the last change") doesn't hold. The code behaves correctly here: a reload that read the latest file should clear the mark. Only the test's ordering is unsynchronized.

How to reproduce

Run cargo test --workspace, or the rustgis-ui-egui lib tests while other builds or tests load the machine. The test fails now and then. Run on its own, it passes. To make it fail every time, add std::thread::sleep(std::time::Duration::from_millis(50)); at the start of the reload thread's closure in readjob::start. Here it then failed 3 of 3 runs, each time with left: Unchanged.

Proposal

Have the test wait until the first reload's thread has looked at the file before it calls replace(3). A test-only helper in readjob can do this, for example pub(crate) fn looked_for_tests(app: &RustGisApp) -> bool, true once the running job's seen slot holds what its thread observed. Poll it with the same 30 s deadline as land_all:

app.run("ui.reloadData", json!({"layer": id})).unwrap();
let end = std::time::Instant::now() + std::time::Duration::from_secs(30);
while !crate::readjob::looked_for_tests(&app) {
    assert!(std::time::Instant::now() < end, "the first reload never looked at its file");
    std::thread::sleep(std::time::Duration::from_millis(1));
}
replace(3);

Choices in this proposal

  • Wait for the look, not the read. The test needs the first reload to have seen version 2 while it is still in flight, so that the second reload queues behind it. Waiting until the first one lands would remove the queued case that the test is about.
  • A test-only helper, no production change. The behaviour is right; only the test's ordering needs a synchronization point.
  • No retry or #[ignore]. Either one would hide the race instead of removing it.

🤖 Generated with Claude Code

Activity

  1. elpidioassinaturas commented on Nov 13, 2026

    @elpidioassinaturas
    ContributorAuthor

    Fixed on main by #1963, which makes the test wait for the first reload's read before it changes the file. #1963 doesn't close this issue, so I'll leave closing it to the maintainers.

  2. elpidioassinaturas commented on Nov 14, 2026

    @elpidioassinaturas
    ContributorAuthor

    Closing as fixed by #1963.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions