Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: mocha timeout test doesn't time out
  • Loading branch information
strophy committed Jun 28, 2022
commit 4e04dd0440173939440743073d997b5dfbaf2979
46 changes: 27 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,24 +525,32 @@ describe('RpcClient', function() {

});

});

it('should throw error when timeout is triggered', (done) => {
var client = new RpcClient({
user: 'user',
pass: 'pass',
host: '127.0.0.1',
port: 1000,
});
it('should throw error when timeout is triggered', (done) => {
var client = new RpcClient({
user: 'user',
pass: 'pass',
host: 'localhost',
port: 8332,
});

client.httpOptions = {
timeout: 100
};
client.httpOptions = {
timeout: 100
};

var requestStub = sinon.stub(client.protocol, 'request').callsFake(function (options, callback) {
var req = new FakeRequest();
setTimeout(function () {
req.emit('timeout');
}, options.timeout + 200);
return req;
});

client.getDifficulty((error, parsedBuf) => {
should.exist(error);
should.not.exist(parsedBuf);
error.message.should.equal('Timeout Error: 100ms exceeded')
done();
})
});
client.getDifficulty((error, parsedBuf) => {
should.exist(error);
should.not.exist(parsedBuf);
error.message.should.equal(`Timeout Error: ${client.httpOptions.timeout}ms exceeded`);
requestStub.restore();
done();
})
});
})