@@ -24,15 +24,14 @@ import {Chunker} from '../../src/v1/internal/chunking';
2424import { alloc } from '../../src/v1/internal/buf' ;
2525import { Neo4jError , newError , SERVICE_UNAVAILABLE } from '../../src/v1/error' ;
2626import 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' ;
2828import lolex from 'lolex' ;
2929import Logger from '../../src/v1/internal/logger' ;
3030import StreamObserver from '../../src/v1/internal/stream-observer' ;
3131import ConnectionErrorHandler from '../../src/v1/internal/connection-error-handler' ;
3232import testUtils from '../internal/test-utils' ;
3333import Bookmark from '../../src/v1/internal/bookmark' ;
3434import TxConfig from '../../src/v1/internal/tx-config' ;
35- import boltStub from '../internal/bolt-stub' ;
3635
3736const ILLEGAL_MESSAGE = { signature : 42 , fields : [ ] } ;
3837const SUCCESS_MESSAGE = { signature : 0x70 , fields : [ { } ] } ;
@@ -347,27 +346,25 @@ describe('Connection', () => {
347346 connection . _handleFatalError ( newError ( 'Hello' , SERVICE_UNAVAILABLE ) ) ;
348347 } ) ;
349348
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 ) ;
355353
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 ) ;
371368 } ) ;
372369
373370 function packedHandshakeMessage ( ) {
@@ -446,4 +443,12 @@ describe('Connection', () => {
446443 return Connection . create ( url , config || { } , new ConnectionErrorHandler ( errorCode || SERVICE_UNAVAILABLE ) , Logger . noOp ( ) ) ;
447444 }
448445
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+
449454} ) ;
0 commit comments