mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 16:13:12 +09:00
Add tests for loopbacks
This commit is contained in:
2 files changed
+50
No files matched your search
@@ -189,6 +189,12 @@ before(async function() {
|
|||||||
format: new lib.TerminalFormat(),
|
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(instancesDir);
|
||||||
await fs.remove(modsDir);
|
await fs.remove(modsDir);
|
||||||
await fs.remove(databaseDir);
|
await fs.remove(databaseDir);
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ const lib = require("@clusterio/lib");
|
|||||||
const { Host, Instance, InstanceConnection } = require("@clusterio/host");
|
const { Host, Instance, InstanceConnection } = require("@clusterio/host");
|
||||||
const { ControlConnection, Controller, HostConnection, InstanceInfo } = require("@clusterio/controller");
|
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;
|
const addr = lib.Address.fromShorthand;
|
||||||
|
|
||||||
class Control extends lib.Link { }
|
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}.`)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user