tests: add writeFull interrupt-handling regression test

This commit verifies that `writeFull` with `allowInterrupts=false` completes
successfully when the interrupt flag is set. This prevents regressions
like the one fixed by #15255 where `write()` called `checkInterrupt()`
unconditionally.
This commit is contained in:
Amaan Qureshi
2026-02-23 11:23:13 -05:00
parent afccf1d2d3
commit 6cddf03b5a

View File

@@ -3,6 +3,7 @@
#include "nix/util/file-descriptor.hh"
#include "nix/util/serialise.hh"
#include "nix/util/signals.hh"
#include <cstring>
@@ -243,4 +244,25 @@ TEST(BufferedSourceReadLine, BufferExhaustedThenEof)
EXPECT_EQ(source.readLine(/*eofOk=*/true), "");
}
TEST(WriteFull, RespectsAllowInterrupts)
{
Pipe pipe;
pipe.create();
setInterrupted(true);
// Must not throw Interrupted even though the interrupt flag is set.
EXPECT_NO_THROW(writeFull(pipe.writeSide.get(), "hello", /*allowInterrupts=*/false));
// Must throw Interrupted when allowInterrupts is true.
EXPECT_THROW(writeFull(pipe.writeSide.get(), "hello", /*allowInterrupts=*/true), Interrupted);
setInterrupted(false);
pipe.writeSide.close();
// Verify the data from the first write was actually written.
FdSource source(pipe.readSide.get());
EXPECT_EQ(source.readLine(/*eofOk=*/true), "hello");
}
} // namespace nix