Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacgr committed Oct 8, 2023
1 parent 30d337f commit 59d8a2c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
4 changes: 1 addition & 3 deletions src/client/protocol/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ class JsonRpcClientProtocol {
this.listen();
resolve(this.server);
});
this.connector.on("error", (error) =>
this._onConnectionFailed(error, resolve, reject)
);
this.connector.on("error", error => this._onConnectionFailed(error, resolve, reject));
this.connector.on("close", (hadError) => {
if (!hadError) {
this.factory.emit("serverDisconnected");
Expand Down
4 changes: 2 additions & 2 deletions tests/client/http-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ describe("HTTP Client", () => {
.then(() => {
done();
})
.catch((e) => console.log(e));
.catch(e => console.log(e));
});
after((done) => {
serverHttp
.close()
.then(() => {
done();
})
.catch((e) => console.log(e));
.catch(e => console.log(e));
});
describe("connection", () => {
// it("should receive error trying to write while disconnected", (done) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/client/https-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe("HTTPS Client", () => {
.then(() => {
done();
})
.catch((e) => console.log(e));
.catch(e => console.log(e));
});
after((done) => {
serverHttps
.close()
.then(() => {
done();
})
.catch((e) => console.log(e));
.catch(e => console.log(e));
});
describe("connection", () => {
// it("should receive error trying to write while disconnected", (done) => {
Expand Down
82 changes: 41 additions & 41 deletions tests/issues/#123-reconnect-after-serverDisconnected.test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
const { expect } = require("chai");
const Jaysonic = require("../../src");
const { server } = require("../test-server");
const intercept = require("intercept-stdout");

const tcpclient = new Jaysonic.client.tcp({
retries: 10
});

describe("#123 Reconnect after serverDisconnected", () => {
beforeEach(async () => {
await server.listen();
});
afterEach(async () => {
await tcpclient.end();
});
it("should attempt to reconnect at the default rate after receiving a serverDisconnected", async () => {
let reconnectAttempts = 0;
let capturedText = "";
const unhook = intercept((text) => {
capturedText += text;
});
tcpclient.serverDisconnected(async () => {
reconnectAttempts += 1;
tcpclient.pcolInstance = null;
await tcpclient.connect();
});
await tcpclient.connect();
await server.close();
await new Promise((r) => setTimeout(r, 10000));
unhook();
// first re-connect attempt is done without error
// second is done with error and does not trigger the serverDisconnected call
// after which the test should timeout
// 2 attempts, 5s apart 10s total
expect(capturedText).to.equal(
`Failed to connect. Address [127.0.0.1:8100]. Retrying. 9 attempts left.\nFailed to connect. Address [127.0.0.1:8100]. Retrying. 8 attempts left.\n`
);
expect(reconnectAttempts).to.equal(1);
}).timeout(30000);
});
const { expect } = require("chai");
const intercept = require("intercept-stdout");
const Jaysonic = require("../../src");
const { server } = require("../test-server");

const tcpclient = new Jaysonic.client.tcp({
retries: 10
});

describe("#123 Reconnect after serverDisconnected", () => {
beforeEach(async () => {
await server.listen();
});
afterEach(async () => {
await tcpclient.end();
});
it("should attempt to reconnect at the default rate after receiving a serverDisconnected", async () => {
let reconnectAttempts = 0;
let capturedText = "";
const unhook = intercept((text) => {
capturedText += text;
});
tcpclient.serverDisconnected(async () => {
reconnectAttempts += 1;
tcpclient.pcolInstance = null;
await tcpclient.connect();
});
await tcpclient.connect();
await server.close();
await new Promise(r => setTimeout(r, 10000));
unhook();
// first re-connect attempt is done without error
// second is done with error and does not trigger the serverDisconnected call
// after which the test should timeout
// 2 attempts, 5s apart 10s total
expect(capturedText).to.equal(
"Failed to connect. Address [127.0.0.1:8100]. Retrying. 9 attempts left.\nFailed to connect. Address [127.0.0.1:8100]. Retrying. 8 attempts left.\n"
);
expect(reconnectAttempts).to.equal(1);
}).timeout(30000);
});
2 changes: 1 addition & 1 deletion tests/server/http-server-protocol.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("HTTP Server Protocol Status Override", () => {
this.setResponseStatus({ errorCode: 400, status: 301 });
this.gotError(
new Error(
'{"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": 2}'
"{\"jsonrpc\": \"2.0\", \"error\": {\"code\": -32600, \"message\": \"Invalid Request\"}, \"id\": 2}"
)
);
}
Expand Down

0 comments on commit 59d8a2c

Please sign in to comment.