File tree 5 files changed +33
-4
lines changed
neo4j-driver-deno/lib/bolt-connection/channel 5 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ export default class WebSocketChannel {
168
168
return new Promise ( ( resolve , reject ) => {
169
169
if ( this . _ws && this . _ws . readyState !== WS_CLOSED ) {
170
170
this . _open = false
171
+ this . stopReceiveTimeout ( )
171
172
this . _clearConnectionTimeout ( )
172
173
this . _ws . onclose = ( ) => resolve ( )
173
174
this . _ws . close ( )
@@ -206,7 +207,7 @@ export default class WebSocketChannel {
206
207
* Start the receive timeout for the channel.
207
208
*/
208
209
startReceiveTimeout ( ) {
209
- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210
+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210
211
this . _receiveTimeoutStarted = true
211
212
this . _resetTimeout ( )
212
213
}
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ export default class DenoChannel {
150
150
async close ( ) {
151
151
if ( this . _open ) {
152
152
this . _open = false
153
+ this . stopReceiveTimeout ( )
153
154
if ( this . _conn != null ) {
154
155
await this . _conn . close ( )
155
156
}
@@ -185,7 +186,7 @@ export default class DenoChannel {
185
186
* Start the receive timeout for the channel.
186
187
*/
187
188
startReceiveTimeout ( ) {
188
- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189
+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189
190
this . _receiveTimeoutStarted = true
190
191
this . _resetTimeout ( )
191
192
}
Original file line number Diff line number Diff line change @@ -412,6 +412,31 @@ describe('WebSocketChannel', () => {
412
412
expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
413
413
} )
414
414
415
+ it ( 'should be cleared when connection closes' , async ( ) => {
416
+ webSocketChannel . startReceiveTimeout ( )
417
+
418
+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 1 )
419
+ expect ( fakeSetTimeout . calls . length ) . toEqual ( 1 )
420
+ expect ( fakeSetTimeout . calls [ 0 ] [ 1 ] ) . toEqual ( receiveTimeout )
421
+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
422
+
423
+ await webSocketChannel . close ( )
424
+
425
+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 1 )
426
+ expect ( fakeSetTimeout . calls . length ) . toEqual ( 1 )
427
+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ 0 ] )
428
+ } )
429
+
430
+ it ( 'should call not setTimeout(receiveTimeout) when connection is closed' , async ( ) => {
431
+ await webSocketChannel . close ( )
432
+
433
+ webSocketChannel . startReceiveTimeout ( )
434
+
435
+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 0 )
436
+ expect ( fakeSetTimeout . calls . length ) . toEqual ( 0 )
437
+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
438
+ } )
439
+
415
440
it ( 'should call setTimeout(receiveTimeout) after stopped' , ( ) => {
416
441
webSocketChannel . startReceiveTimeout ( )
417
442
Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ export default class WebSocketChannel {
168
168
return new Promise ( ( resolve , reject ) => {
169
169
if ( this . _ws && this . _ws . readyState !== WS_CLOSED ) {
170
170
this . _open = false
171
+ this . stopReceiveTimeout ( )
171
172
this . _clearConnectionTimeout ( )
172
173
this . _ws . onclose = ( ) => resolve ( )
173
174
this . _ws . close ( )
@@ -206,7 +207,7 @@ export default class WebSocketChannel {
206
207
* Start the receive timeout for the channel.
207
208
*/
208
209
startReceiveTimeout ( ) {
209
- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210
+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210
211
this . _receiveTimeoutStarted = true
211
212
this . _resetTimeout ( )
212
213
}
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ export default class DenoChannel {
150
150
async close ( ) {
151
151
if ( this . _open ) {
152
152
this . _open = false
153
+ this . stopReceiveTimeout ( )
153
154
if ( this . _conn != null ) {
154
155
await this . _conn . close ( )
155
156
}
@@ -185,7 +186,7 @@ export default class DenoChannel {
185
186
* Start the receive timeout for the channel.
186
187
*/
187
188
startReceiveTimeout ( ) {
188
- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189
+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189
190
this . _receiveTimeoutStarted = true
190
191
this . _resetTimeout ( )
191
192
}
You can’t perform that action at this time.
0 commit comments