Skip to content
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

e2e::directories::dep_on_current_directory spontaneous failure #133

Open
GrigorenkoPV opened this issue Jan 14, 2025 · 4 comments
Open

e2e::directories::dep_on_current_directory spontaneous failure #133

GrigorenkoPV opened this issue Jan 14, 2025 · 4 comments

Comments

@GrigorenkoPV
Copy link
Contributor

GrigorenkoPV commented Jan 14, 2025

Got this spontaneous failure, cannot reproduce:

---- e2e::directories::dep_on_current_directory stdout ----

thread 'e2e::directories::dep_on_current_directory' panicked at tests/e2e/directories.rs:21:5:
assertion `left == right` failed
  left: [98, 117, 105, 108, 100, 46, 110, 105, 110, 106, 97, 10, 102, 111, 111, 10, 111, 117, 116, 10]
 right: [98, 117, 105, 108, 100, 46, 110, 105, 110, 106, 97, 10, 102, 111, 111, 10, 102, 111, 111, 50, 10, 111, 117, 116, 10]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The bytes are, correspondingly,

b"build.ninja\nfoo\nout\n"

and

b"build.ninja\nfoo\nfoo2\nout\n"

The code in question:

#[cfg(unix)]
#[test]
fn dep_on_current_directory() -> anyhow::Result<()> {
let space = TestSpace::new()?;
space.write(
"build.ninja",
"
rule list_files
command = ls $in > $out
build out: list_files .
",
)?;
space.write("foo", "")?;
space.run_expect(&mut n2_command(vec!["out"]))?;
assert_eq!(space.read("out")?, b"build.ninja\nfoo\nout\n");
space.write("foo2", "")?;
space.run_expect(&mut n2_command(vec!["out"]))?;
assert_eq!(space.read("out")?, b"build.ninja\nfoo\nfoo2\nout\n");

Maybe a race condition between tests or a buffer did not get flushed?

@evmar
Copy link
Owner

evmar commented Jan 14, 2025

That does look like a race, hmm. The test runner runs the e2e tests in parallel threads, but they each spawn a separate n2 process so there should be no buffering-related issues.

But the threads do each create their own temp dir. Those appear to use a thread-local random number generator... is it possible each thread has the same seed? I would expect more races in that case.

@evmar
Copy link
Owner

evmar commented Jan 14, 2025

Oh wait, looking at the test, more likely it just didn't notice the directory changed. I will fix it.

@evmar
Copy link
Owner

evmar commented Jan 14, 2025

I am sorta not sure what is going on here, because if the test usually passes that means we do see directory modifications.

It looks like stat has high resolution on Linux:
https://github.com/rust-lang/rust/blob/3736b85779d1db4c215b910004d7efcd7aff8408/library/std/src/sys/pal/unix/fs.rs#L488

@evmar evmar changed the title e2e::directories::dep_on_current_directory failure e2e::directories::dep_on_current_directory spontaneous failure Jan 15, 2025
evmar added a commit that referenced this issue Jan 15, 2025
Was looking due to #133 but I do not see the issue.
evmar added a commit that referenced this issue Jan 15, 2025
Was looking due to #133 but I do not see the issue.
@GrigorenkoPV
Copy link
Contributor Author

but they each spawn a separate n2 process so there should be no buffering-related issues.

I mean flushing the file contents to disk after TestSpace::write, but it seems to be using std::fs::write under the hood, so probably that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants