From 6cddf03b5a3dbef47734cc99aecaa7d5b7fe6ff0 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Mon, 23 Feb 2026 11:23:13 -0500 Subject: [PATCH] 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. --- src/libutil-tests/file-descriptor.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libutil-tests/file-descriptor.cc b/src/libutil-tests/file-descriptor.cc index d8f438af5..0c83d9d9b 100644 --- a/src/libutil-tests/file-descriptor.cc +++ b/src/libutil-tests/file-descriptor.cc @@ -3,6 +3,7 @@ #include "nix/util/file-descriptor.hh" #include "nix/util/serialise.hh" +#include "nix/util/signals.hh" #include @@ -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