@@ -25,10 +25,14 @@ let serverStreamCount = 0;
2525// Server allows only 1 bidi stream at a time.
2626const serverEndpoint = await listen ( mustCall ( ( serverSession ) => {
2727 serverSession . onstream = mustCall ( async ( stream ) => {
28- const streambytes = await bytes ( stream ) ;
28+ console . log ( "server mark 1" )
29+ await bytes ( stream ) ;
30+ console . log ( "server mark 2" )
2931 stream . writer . endSync ( ) ;
32+ console . log ( "server mark 3" )
3033 await stream . closed ;
3134 ++ serverStreamCount ;
35+ console . log ( 'serverStreamCount' , serverStreamCount )
3236 if ( serverStreamCount === 2 ) {
3337 twoDone . resolve ( ) ;
3438 }
@@ -38,7 +42,7 @@ const serverEndpoint = await listen(mustCall((serverSession) => {
3842 if ( serverStreamCount === 4 ) {
3943 serverSession . close ( ) ;
4044 }
41- } , 4 ) ;
45+ } , 3 ) ;
4246} ) , {
4347 transportParams : { initialMaxStreamsBidi : 1 } ,
4448} ) ;
@@ -51,38 +55,36 @@ let opened = 0;
5155// First stream opens immediately (within the limit).
5256const s1 = await clientSession . createBidirectionalStream ( {
5357 body : encoder . encode ( 'stream 1' ) ,
54- waitUntilAvailable : true
5558} ) ;
5659
5760// eslint-disable-next-line node-core/must-call-assert
5861s1 . opened . then ( ( ) => {
5962 opened ++ ;
6063} ) ;
6164
62- try {
63- // Second stream should not open, but throw.
64- const s2 = await clientSession . createBidirectionalStream ( {
65- body : encoder . encode ( 'stream 2' ) ,
66- waitUntilAvailable : false
67- } ) ;
68- } catch ( error ) {
69- assert . strictEqual ( error . code , 'ERR_INVALID_STATE' ) ;
70- }
71-
72- // eslint-disable-next-line node-core/must-call-assert
73- s2 . opened . then ( ( ) => {
74- opened ++ ;
75- } ) ;
76-
65+ await assert . rejects (
66+ async ( ) => {
67+ // Second stream should not open, but throw.
68+ await clientSession . createBidirectionalStream ( {
69+ body : encoder . encode ( 'stream 2' ) ,
70+ waitUntilAvailable : false ,
71+ } ) ;
72+ // eslint-disable-next-line node-core/must-call-assert
73+ s2 . opened . then ( ( ) => {
74+ opened ++ ;
75+ } ) ;
76+ } ,
77+ {
78+ name : 'Error' ,
79+ message : 'No new stream available within flow control' ,
80+ } ,
81+ ) ;
7782// Third stream is created but queued as pending because the
7883// server only allows 1 concurrent bidi stream.
7984const s3 = await clientSession . createBidirectionalStream ( {
8085 body : encoder . encode ( 'stream 3' ) ,
81- waitUntilAvailable : true
8286} ) ;
83-
84-
85- // s3 should be pending until s1 closes and the server grants
87+ // Note, s3 should be pending until s1 closes and the server grants
8688// more stream credits.
8789assert . strictEqual ( s3 . pending , true ) ;
8890assert . strictEqual ( opened , 1 ) ;
@@ -96,7 +98,6 @@ s3.destroy(err);
9698
9799await Promise . all ( [ assert . rejects ( s3 . opened , err ) , assert . rejects ( s3 . closed , err ) ] ) ;
98100
99-
100101// After s1 closes, the server sends MAX_STREAMS which opens s2.
101102// Wait for the server to receive both streams.
102103await twoDone . promise ;
@@ -105,14 +106,13 @@ assert.strictEqual(opened, 2);
105106for await ( const _ of s3 ) { /* drain */ } // eslint-disable-line no-unused-vars
106107await s3 . closed ;
107108
108- await sleep ( 10 ) ; // we wait a bit, as we do not have a callback exposed to js
109+ await sleep ( 10 ) ; // We wait a bit, as we do not have a callback exposed to js
109110// fourth stream should open immediately and not throw
110111const s4 = await clientSession . createBidirectionalStream ( {
111112 body : encoder . encode ( 'stream 4' ) ,
112113 waitUntilAvailable : false
113114} ) ;
114- await s4 . closed ;
115- await allDone . promise ;
115+ await Promise . all ( [ s4 . closed , allDone . promise ] ) ;
116116
117117await clientSession . close ( ) ;
118- await serverEndpoint . close ( ) ;
118+ await serverEndpoint . close ( ) ;
0 commit comments