Skip to content

Commit c27b60c

Browse files
authored
Handle swift-testing events > 8kb (#800)
Using Node's built in net.Socket imposes an 8kb message limit on the JSONL writes from swift-testing. This meant that if a test case had a lot of iterations the `test` event would overrun the limit and the message would never be read. Create our own readable stream and manage pausing/resuming the pipe on data/drain events. This allows for swift-testing to write whatever size messages it wants.
1 parent 18201e5 commit c27b60c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/TestExplorer/TestParsers/TestEventStreamReader.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,24 @@ export class UnixNamedPipeReader implements INamedPipeReader {
4343

4444
public async start(readable: Readable) {
4545
return new Promise<void>((resolve, reject) => {
46-
fs.open(this.path, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK, (err, fd) => {
46+
fs.open(this.path, fs.constants.O_RDONLY, (err, fd) => {
47+
if (err) {
48+
return reject(err);
49+
}
4750
try {
48-
const pipe = new net.Socket({ fd, readable: true });
49-
pipe.on("data", data => readable.push(data));
51+
// Create our own readable stream that handles backpressure.
52+
// Using a net.Socket to read the pipe has an 8kb internal buffer,
53+
// meaning we couldn't read from writes that were > 8kb.
54+
const pipe = fs.createReadStream("", { fd });
55+
56+
pipe.on("data", data => {
57+
if (!readable.push(data)) {
58+
pipe.pause();
59+
}
60+
});
61+
62+
readable.on("drain", () => pipe.resume());
63+
5064
pipe.on("error", () => fs.close(fd));
5165
pipe.on("end", () => {
5266
readable.push(null);
@@ -55,7 +69,7 @@ export class UnixNamedPipeReader implements INamedPipeReader {
5569

5670
resolve();
5771
} catch (error) {
58-
reject(error);
72+
fs.close(fd, () => reject(error));
5973
}
6074
});
6175
});

0 commit comments

Comments
 (0)