mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-01 01:25:48 +00:00
Add a heartbeat to detect hung connections (#1101)
* disconnect is now reconnect on heartbeat fail
This commit is contained in:
@@ -266,6 +266,26 @@ describe('Connection', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('reconnect event on heartbeat failure', function(done) {
|
||||
if (isBrowser) {
|
||||
const phantomTest = /PhantomJS/;
|
||||
if (phantomTest.test(navigator.userAgent)) {
|
||||
// inside PhantomJS this one just hangs, so skip as not very relevant
|
||||
done();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Set the heartbeat to less than the 1 second ping response
|
||||
this.api.connection._timeout = 500;
|
||||
// Drop the test runner timeout, since this should be a quick test
|
||||
this.timeout(5000);
|
||||
// Hook up a listener for the reconnect event
|
||||
this.api.connection.on('reconnect', () => done());
|
||||
// Trigger a heartbeat
|
||||
this.api.connection._heartbeat();
|
||||
});
|
||||
|
||||
|
||||
it('should emit disconnected event with code 1000 (CLOSE_NORMAL)',
|
||||
function(done
|
||||
) {
|
||||
|
||||
@@ -336,6 +336,19 @@ export function createMockRippled(port) {
|
||||
}
|
||||
});
|
||||
|
||||
mock.on('request_ping', function (request, conn) {
|
||||
// NOTE: We give the response a timeout of 2 second, so that tests can
|
||||
// set their timeout threshold to greater than or less than this number
|
||||
// to test timeouts.
|
||||
setTimeout(() => {
|
||||
conn.send(createResponse(request, {
|
||||
"result": {},
|
||||
"status": "success",
|
||||
"type": "response"
|
||||
}));
|
||||
}, 1000 * 2);
|
||||
});
|
||||
|
||||
mock.on('request_tx', function (request, conn) {
|
||||
assert.strictEqual(request.command, 'tx');
|
||||
if (request.transaction === hashes.VALID_TRANSACTION_HASH) {
|
||||
|
||||
Reference in New Issue
Block a user