Add tests for loopbacks

This commit is contained in:
Cooldude2606 committed 2024-05-18 03:33:55 +01:00
1 parent b9e9a754b8
commit fb4a5e40f3
2 files changed
+50

No files matched your search

+6
View File
@@ -189,6 +189,12 @@ before(async function() {
format: new lib.TerminalFormat(),
}));
// If fast test is enabled then output that it is
// eslint-disable-next-line node/no-process-env
if (process.env.FAST_TEST) {
console.log("FAST_TEST is present in env, slow tests will be skipped.");
}
await fs.remove(instancesDir);
await fs.remove(modsDir);
await fs.remove(databaseDir);
+44
View File
@@ -5,6 +5,9 @@ const lib = require("@clusterio/lib");
const { Host, Instance, InstanceConnection } = require("@clusterio/host");
const { ControlConnection, Controller, HostConnection, InstanceInfo } = require("@clusterio/controller");
// Although there are no imports, the file has side-effects such as "before" which can effect tests
require("./index");
const addr = lib.Address.fromShorthand;
class Control extends lib.Link { }
@@ -419,4 +422,45 @@ describe("Integration of link routing", function() {
});
}
});
describe("event should not be routable on loopback", function() {
it("should not loopback on controller", async function() {
// Sending an event never returns a promise, so it throws rather than rejects like a request
assert.throws(
() => send(get("controller"), addr("controller"), new TestEvent()),
new Error("controller as dst is not supported.")
);
});
for (const srcName of ["hostA", "instanceA1", "controlA"]) {
it(`should not loopback on ${srcName}`, async function() {
const src = get(srcName);
const dstAddr = src.connector.src;
assert.throws(
() => send(src, dstAddr, new TestEvent()),
new Error(`Message would return back to sender ${dstAddr}.`)
);
});
}
});
describe("request should not be routable on loopback", function() {
it("should not loopback on controller", async function() {
await assert.rejects(
() => send(get("controller"), addr("controller"), new TestRequest()),
new Error("controller as dst is not supported.")
);
});
for (const srcName of ["hostA", "instanceA1", "controlA"]) {
it(`should not loopback on ${srcName}`, async function() {
const src = get(srcName);
const dstAddr = src.connector.src;
await assert.rejects(
() => send(src, dstAddr, new TestRequest()),
new Error(`Message would return back to sender ${dstAddr}.`)
);
});
}
});
});