(sync)
| 25 | runTests(true); |
| 26 | |
| 27 | function runTests(sync) { |
| 28 | |
| 29 | { |
| 30 | const dest = getTempFile(); |
| 31 | const fd = openSync(dest, 'w'); |
| 32 | const stream = new Utf8Stream({ fd, sync, minLength: 5000 }); |
| 33 | |
| 34 | assert.ok(stream.write('hello world\n')); |
| 35 | |
| 36 | setTimeout(common.mustCall(() => { |
| 37 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 38 | assert.strictEqual(data, ''); |
| 39 | })); |
| 40 | }), 1500); |
| 41 | |
| 42 | stream.destroy(); |
| 43 | } |
| 44 | |
| 45 | { |
| 46 | const dest = getTempFile(); |
| 47 | const fd = openSync(dest, 'w'); |
| 48 | |
| 49 | // Test that periodicFlush property is set correctly |
| 50 | const stream1 = new Utf8Stream({ fd, sync, minLength: 5000 }); |
| 51 | assert.strictEqual(stream1.periodicFlush, 0); |
| 52 | stream1.destroy(); |
| 53 | |
| 54 | const fd2 = openSync(dest, 'w'); |
| 55 | const stream2 = new Utf8Stream({ fd: fd2, sync, minLength: 5000, periodicFlush: 1000 }); |
| 56 | assert.strictEqual(stream2.periodicFlush, 1000); |
| 57 | stream2.destroy(); |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | const dest = getTempFile(); |
| 62 | const fd = openSync(dest, 'w'); |
| 63 | const stream = new Utf8Stream({ fd, sync, minLength: 5000 }); |
| 64 | |
| 65 | assert.ok(stream.write('hello world\n')); |
| 66 | |
| 67 | // Manually flush to test that data can be written |
| 68 | stream.flush(common.mustSucceed()); |
| 69 | |
| 70 | setTimeout(common.mustCall(() => { |
| 71 | readFile(dest, 'utf8', common.mustSucceed((data) => { |
| 72 | assert.strictEqual(data, 'hello world\n'); |
| 73 | })); |
| 74 | }), 500); |
| 75 | |
| 76 | stream.destroy(); |
| 77 | } |
| 78 | } |
no test coverage detected
searching dependent graphs…