Files
factorio-clusterio/test/integration/link.js
T
Hornwitser 1de8b76303 Emit resume instead of connect on resumed connections
Raise "resume" instead of "connect" when a connection is re-established
after a connection drop.  This prevents logic meant to resynchronize
state after a full reconnection from being invoked whenever the
connection was temporarily dropped.
2021-02-19 14:28:19 +01:00

57 lines
1.8 KiB
JavaScript

"use strict";
const assert = require("assert").strict;
const events = require("events");
const fs = require("fs-extra");
const jwt = require("jsonwebtoken");
const { TestControlConnector, TestControl, get, exec, url } = require("./index");
let token = jwt.sign({ aud: "user", user: "test" }, "TestSecretDoNotUse");
describe("Integration of lib/link", function() {
let tlsCa;
let control;
let controlConnector;
before(async function() {
tlsCa = await fs.readFile("test/file/tls/cert.pem");
});
it("should emitt an error if authentication failed", async function() {
controlConnector = new TestControlConnector(url, 0.2, tlsCa);
controlConnector.token = "gibberish";
control = new TestControl(controlConnector);
await assert.rejects(
controlConnector.connect(),
new Error("Authentication failed: jwt malformed")
);
});
it("should connect with proper credentials", async function() {
controlConnector = new TestControlConnector(url, 0.2, tlsCa);
controlConnector.token = token;
control = new TestControl(controlConnector);
await controlConnector.connect();
});
it("should reconnect on connection lost", async function() {
controlConnector._socket.close(1008, "Test");
await events.once(controlConnector, "resume");
});
it("should reconnect on connection terminated", async function() {
controlConnector._socket.terminate();
await events.once(controlConnector, "resume");
});
it("should reconnect on connection heartbeat timeout", async function() {
controlConnector.stopHeartbeat();
await events.once(controlConnector, "resume");
});
it("should invalidate on reconnection with bad session token", async function() {
controlConnector._sessionToken = "blah";
controlConnector.stopHeartbeat();
await events.once(controlConnector, "invalidate");
await events.once(controlConnector, "connect");
});
});