@@ -18,6 +18,7 @@ var RC = require('./RC');
1818var HazelcastClient = require ( '../.' ) . Client ;
1919var expect = require ( 'chai' ) . expect ;
2020var Config = require ( '../.' ) . Config ;
21+ var Util = require ( './Util' ) ;
2122
2223describe ( 'Heartbeat' , function ( ) {
2324 this . timeout ( 30000 ) ;
@@ -52,7 +53,7 @@ describe('Heartbeat', function() {
5253 return member . address . host + ':' + member . address . port ;
5354 }
5455 } ;
55- warmUpConnectionToAddress ( client , address ) ;
56+ warmUpConnectionToAddressWithRetry ( client , address ) ;
5657 } ) ;
5758 client . heartbeat . addListener ( { onHeartbeatStopped : function ( connection ) {
5859 client . shutdown ( ) ;
@@ -78,16 +79,9 @@ describe('Heartbeat', function() {
7879 } ) . then ( function ( resp ) {
7980 client = resp ;
8081 client . clusterService . on ( 'memberAdded' , function ( member ) {
81- var address = {
82- host : member . address . host ,
83- port : member . address . port ,
84- toString : function ( ) {
85- return member . address . host + ':' + member . address . port ;
86- }
87- } ;
88- warmUpConnectionToAddress ( client , address ) . then ( function ( ) {
89- simulateHeartbeatLost ( client , address , 2000 ) ;
90- } ) ;
82+ warmUpConnectionToAddressWithRetry ( client , member . address , 3 ) . then ( function ( ) {
83+ simulateHeartbeatLost ( client , member . address , 2000 ) ;
84+ } ) . catch ( done ) ;
9185 } ) ;
9286 client . heartbeat . addListener ( { onHeartbeatRestored : function ( connection ) {
9387 client . shutdown ( ) ;
@@ -126,7 +120,17 @@ describe('Heartbeat', function() {
126120 client . connectionManager . establishedConnections [ address ] . lastRead = client . connectionManager . establishedConnections [ address ] . lastRead - timeout ;
127121 }
128122
129- function warmUpConnectionToAddress ( client , address ) {
130- return client . connectionManager . getOrConnect ( address ) ;
123+ function warmUpConnectionToAddressWithRetry ( client , address , retryCount ) {
124+ return client . connectionManager . getOrConnect ( address ) . then ( function ( conn ) {
125+ if ( conn != null ) {
126+ return conn ;
127+ } else if ( conn == null && retryCount > 0 ) {
128+ return Util . promiseWaitMilliseconds ( 300 ) . then ( function ( ) {
129+ return warmUpConnectionToAddressWithRetry ( client , address , retryCount - 1 ) ;
130+ } ) ;
131+ } else {
132+ throw new Error ( 'Could not warm up connection to ' + address ) ;
133+ }
134+ } ) ;
131135 }
132136} ) ;
0 commit comments