Skip to content

Commit

Permalink
Add test for infinite retries. Refs #94.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacgr committed Aug 22, 2021
1 parent 678b161 commit 9e82f51
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/connections/base-client-protocol.test.js
Expand Up @@ -3,6 +3,7 @@ const intercept = require("intercept-stdout");
const Jaysonic = require("../../src");

const client = new Jaysonic.client.tcp({ retries: 1 });
const infClient = new Jaysonic.client.tcp({ retries: Infinity });

describe("Base Client Reconnect", () => {
it("should retry the connection to the server and log the attempts", (done) => {
Expand All @@ -14,11 +15,26 @@ describe("Base Client Reconnect", () => {
setTimeout(() => {
unhook();
expect(capturedText).to.equal(
"Unable to connect. Retrying. 0 attempts left.\n"
"Failed to connect. Address [127.0.0.1:8100]. Retrying. 0 attempts left.\n"
);
}, 100);
conn.catch(() => {
done();
});
}).timeout(10000);
it("should retry the connection to the server indefinitely if retries set to 'Infinity'", (done) => {
infClient.connect();
let capturedText = "";
const unhook = intercept((text) => {
capturedText += text;
});
setTimeout(() => {
unhook();
expect(capturedText).to.equal(
"Failed to connect. Address [127.0.0.1:8100]. Retrying.\n"
);
infClient.end();
done();
}, 100);
}).timeout(10000);
});

0 comments on commit 9e82f51

Please sign in to comment.