@@ -53,12 +53,17 @@ const s1 = await clientSession.createBidirectionalStream({
5353 body : encoder . encode ( 'stream 1' ) ,
5454} ) ;
5555
56- let s2
56+ // eslint-disable-next-line node-core/must-call-assert
57+ s1 . opened . then ( ( ) => {
58+ opened ++ ;
59+ } ) ;
60+
61+ let s2 ;
5762await assert . rejects (
5863 async ( ) => {
5964 // Second stream should not open, but throw.
6065 s2 = await clientSession . createBidirectionalStream ( {
61- body : encoder . encode ( 'stream 2 ' ) ,
66+ body : encoder . encode ( 'stream 2a ' ) ,
6267 waitUntilAvailable : false ,
6368 } ) ;
6469 // eslint-disable-next-line node-core/must-call-assert
@@ -71,6 +76,15 @@ await assert.rejects(
7176 message : 'No new stream available within flow control' ,
7277 } ,
7378) ;
79+ // Ok try again a second second stream, that patiently waits
80+ s2 = await clientSession . createBidirectionalStream ( {
81+ body : encoder . encode ( 'stream 2b' )
82+ } ) ;
83+ // eslint-disable-next-line node-core/must-call-assert
84+ s2 . opened . then ( ( ) => {
85+ opened ++ ;
86+ } ) ;
87+
7488
7589// Third stream is created but queued as pending because the
7690// server only allows 1 concurrent bidi stream.
@@ -79,13 +93,11 @@ const s3 = await clientSession.createBidirectionalStream({
7993} ) ;
8094
8195
82- // s2 should be pending until s1 closes and the server grants
96+ // s2 and s3 should be pending until s1 closes and the server grants
8397// more stream credits.
8498assert . strictEqual ( s2 . pending , true ) ;
85- assert . strictEqual ( opened , 1 ) ;
86- // s3 should be pending until s1 closes and the server grants
87- // more stream credits.
8899assert . strictEqual ( s3 . pending , true ) ;
100+ assert . strictEqual ( opened , 1 ) ;
89101
90102// Drain and close the first stream.
91103for await ( const _ of s1 ) { /* drain */ } // eslint-disable-line no-unused-vars
0 commit comments