|
6 | 6 |
|
7 | 7 | const common = require('../common'); |
8 | 8 | const assert = require('assert'); |
| 9 | +const { once } = require('events'); |
9 | 10 | const { setImmediate, setTimeout } = require('timers/promises'); |
10 | 11 | const { |
11 | 12 | push, |
@@ -603,18 +604,33 @@ async function testDestroyWithoutFail() { |
603 | 604 | } |
604 | 605 |
|
605 | 606 | // ============================================================================= |
606 | | -// Custom highWaterMark option |
| 607 | +// Classic Writable backpressure |
607 | 608 | // ============================================================================= |
608 | 609 |
|
609 | | -function testHighWaterMarkIsMaxSafeInt() { |
| 610 | +function testUsesBoundedHighWaterMark() { |
610 | 611 | const writer = { |
611 | 612 | write(chunk) { return Promise.resolve(); }, |
612 | 613 | }; |
613 | 614 |
|
614 | | - // HWM is set to MAX_SAFE_INTEGER to disable Writable's internal |
615 | | - // buffering. The underlying Writer manages backpressure directly. |
616 | 615 | const writable = toWritable(writer); |
617 | | - assert.strictEqual(writable.writableHighWaterMark, Number.MAX_SAFE_INTEGER); |
| 616 | + assert.ok(writable.writableHighWaterMark > 0); |
| 617 | + assert.ok(writable.writableHighWaterMark < Number.MAX_SAFE_INTEGER); |
| 618 | +} |
| 619 | + |
| 620 | +async function testAppliesClassicBackpressure() { |
| 621 | + let resolveWrite; |
| 622 | + const writable = toWritable({ |
| 623 | + write: common.mustCall(() => new Promise((resolve) => { |
| 624 | + resolveWrite = resolve; |
| 625 | + })), |
| 626 | + }); |
| 627 | + const chunk = Buffer.alloc(writable.writableHighWaterMark); |
| 628 | + |
| 629 | + assert.strictEqual(writable.write(chunk), false); |
| 630 | + const finished = once(writable, 'finish'); |
| 631 | + resolveWrite(); |
| 632 | + writable.end(); |
| 633 | + await finished; |
618 | 634 | } |
619 | 635 |
|
620 | 636 | // ============================================================================= |
@@ -700,10 +716,11 @@ async function testEndThrowsSyncPropagation() { |
700 | 716 |
|
701 | 717 | testInvalidWriterThrows(); |
702 | 718 | testNoWritevWithoutWriterWritev(); |
703 | | -testHighWaterMarkIsMaxSafeInt(); |
| 719 | +testUsesBoundedHighWaterMark(); |
704 | 720 |
|
705 | 721 | Promise.all([ |
706 | 722 | testBasicWrite(), |
| 723 | + testAppliesClassicBackpressure(), |
707 | 724 | testFalsyWriterRejectionBecomesClassicError(), |
708 | 725 | testClassicWrapperReusePreservesErrorIdentity(), |
709 | 726 | testWriteDelegatesToWriter(), |
|
0 commit comments