Skip to content

Commit

Permalink
Test that subscription error handlers single-fire on close
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Apr 26, 2020
1 parent df2cb4a commit 4a3ef1e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/eth.subscribe.ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,27 @@ describe('subscription connect/reconnect', function () {
});

it('errors when the subscription got established (is running) and the connection does get closed', function () {
this.timeout(5000);
let counter = 0;

return new Promise(async function (resolve) {
web3.eth
.subscribe('newBlockHeaders')
.once('data', async function () {
await pify(server.close)();
})
.once('error', function (err) {
.on('error', function (err) {
counter++;
assert(err.message.includes('CONNECTION ERROR'));
assert(err.message.includes('close code `1006`'));
assert(err.message.includes('Connection dropped by remote peer.'));
resolve();
});

// Make sure error handler doesn't fire twice
await waitSeconds(2);
assert.equal(counter, 1);
web3.eth.currentProvider.removeAllListeners();
resolve();
});
});

Expand Down

0 comments on commit 4a3ef1e

Please sign in to comment.