Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/libutil-tests/file-descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "nix/util/file-descriptor.hh"
#include "nix/util/serialise.hh"
#include "nix/util/signals.hh"

#include <cstring>

Expand Down Expand Up @@ -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
Loading