@@ -24,15 +24,14 @@ import {Chunker} from '../../src/v1/internal/chunking';
24
24
import { alloc } from '../../src/v1/internal/buf' ;
25
25
import { Neo4jError , newError , SERVICE_UNAVAILABLE } from '../../src/v1/error' ;
26
26
import sharedNeo4j from '../internal/shared-neo4j' ;
27
- import { ServerVersion } from '../../src/v1/internal/server-version' ;
27
+ import { ServerVersion , VERSION_3_5_0 } from '../../src/v1/internal/server-version' ;
28
28
import lolex from 'lolex' ;
29
29
import Logger from '../../src/v1/internal/logger' ;
30
30
import StreamObserver from '../../src/v1/internal/stream-observer' ;
31
31
import ConnectionErrorHandler from '../../src/v1/internal/connection-error-handler' ;
32
32
import testUtils from '../internal/test-utils' ;
33
33
import Bookmark from '../../src/v1/internal/bookmark' ;
34
34
import TxConfig from '../../src/v1/internal/tx-config' ;
35
- import boltStub from '../internal/bolt-stub' ;
36
35
37
36
const ILLEGAL_MESSAGE = { signature : 42 , fields : [ ] } ;
38
37
const SUCCESS_MESSAGE = { signature : 0x70 , fields : [ { } ] } ;
@@ -347,27 +346,25 @@ describe('Connection', () => {
347
346
connection . _handleFatalError ( newError ( 'Hello' , SERVICE_UNAVAILABLE ) ) ;
348
347
} ) ;
349
348
350
- it ( 'should send hello and goodbye messages' , done => {
351
- if ( ! boltStub . supported ) {
352
- done ( ) ;
353
- return ;
354
- }
349
+ it ( 'should send INIT/HELLO and GOODBYE messages' , done => {
350
+ const messages = [ ] ;
351
+ connection = createConnection ( 'bolt://localhost' ) ;
352
+ recordWrittenMessages ( connection , messages ) ;
355
353
356
- const server = boltStub . start ( './test/resources/boltstub/hello_goodbye.script' , 9001 ) ;
357
-
358
- boltStub . run ( ( ) => {
359
- connection = createConnection ( 'bolt://127.0.0.1:9001' , { encrypted : false } ) ;
360
- connection . connect ( 'single-connection/1.2.3' , basicAuthToken ( ) )
361
- . then ( ( ) => {
362
- connection . close ( ( ) => {
363
- server . exit ( code => {
364
- expect ( code ) . toEqual ( 0 ) ;
365
- done ( ) ;
366
- } ) ;
367
- } ) ;
368
- } )
369
- . catch ( error => done . fail ( error ) ) ;
370
- } ) ;
354
+ connection . connect ( 'mydriver/0.0.0' , basicAuthToken ( ) )
355
+ . then ( ( ) => {
356
+ expect ( connection . isOpen ( ) ) . toBeTruthy ( ) ;
357
+ connection . close ( ( ) => {
358
+ expect ( messages . length ) . toBeGreaterThan ( 0 ) ;
359
+ expect ( messages [ 0 ] . signature ) . toEqual ( 0x01 ) ; // first message is either INIT or HELLO
360
+
361
+ const serverVersion = ServerVersion . fromString ( connection . server . version ) ;
362
+ if ( serverVersion . compareTo ( VERSION_3_5_0 ) >= 0 ) {
363
+ expect ( messages [ messages . length - 1 ] . signature ) . toEqual ( 0x02 ) ; // last message is GOODBYE in V3
364
+ }
365
+ done ( ) ;
366
+ } ) ;
367
+ } ) . catch ( done . fail ) ;
371
368
} ) ;
372
369
373
370
function packedHandshakeMessage ( ) {
@@ -446,4 +443,12 @@ describe('Connection', () => {
446
443
return Connection . create ( url , config || { } , new ConnectionErrorHandler ( errorCode || SERVICE_UNAVAILABLE ) , Logger . noOp ( ) ) ;
447
444
}
448
445
446
+ function recordWrittenMessages ( connection , messages ) {
447
+ const originalWrite = connection . write . bind ( connection ) ;
448
+ connection . write = ( message , observer , flush ) => {
449
+ messages . push ( message ) ;
450
+ originalWrite ( message , observer , flush ) ;
451
+ } ;
452
+ }
453
+
449
454
} ) ;
0 commit comments