Skip to content

Commit 66be975

Browse files
committed
refactor heartbeat test: custom address object is not neccessary any more
1 parent be07bb7 commit 66be975

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

test/HeartbeatTest.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var RC = require('./RC');
1818
var HazelcastClient = require('../.').Client;
1919
var expect = require('chai').expect;
2020
var Config = require('../.').Config;
21+
var Util = require('./Util');
2122

2223
describe('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

Comments
 (0)