mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Add sendOrderedRcon for plugins
Add BaseInstancePlugin method for sending RCON commands in order to simplify logic in plugins that depend on commands being delivered in order.
This commit is contained in:
1 parent
e8b515c733
commit
c40362fa7f
3 files changed
+113
-3
No files matched your search
+31
-1
@@ -10,7 +10,7 @@ describe("lib/plugin", function() {
|
||||
describe("class BaseInstancePlugin", function() {
|
||||
let instancePlugin;
|
||||
it("should be constructible", async function() {
|
||||
instancePlugin = new libPlugin.BaseInstancePlugin({}, { logger: new mock.MockLogger() }, {});
|
||||
instancePlugin = new libPlugin.BaseInstancePlugin({}, new mock.MockInstance(), {});
|
||||
await instancePlugin.init();
|
||||
});
|
||||
it("should define defaults for hooks", async function() {
|
||||
@@ -22,6 +22,36 @@ describe("lib/plugin", function() {
|
||||
instancePlugin.onMasterConnectionEvent("connect");
|
||||
await instancePlugin.onPrepareMasterDisconnect();
|
||||
});
|
||||
describe("sendRcon", function() {
|
||||
it("should send commands out of order", async function() {
|
||||
instancePlugin.instance.server.rconCommandResults.set("a", { time: 100, response: "a" });
|
||||
instancePlugin.instance.server.rconCommandResults.set("b", { time: 50, response: "b" });
|
||||
|
||||
let a = instancePlugin.sendRcon("a");
|
||||
let b = instancePlugin.sendRcon("b");
|
||||
let result = await Promise.race([a, b]);
|
||||
assert.equal(result, "b");
|
||||
});
|
||||
it("should propagate errors", async function() {
|
||||
instancePlugin.instance.server.rconCommandResults.set("a", new Error("ref"));
|
||||
await assert.rejects(instancePlugin.sendRcon("a"), new Error("ref"));
|
||||
});
|
||||
});
|
||||
describe("sendOrderedRcon", function() {
|
||||
it("should send commands in order", async function() {
|
||||
instancePlugin.instance.server.rconCommandResults.set("a", { time: 100, response: "a" });
|
||||
instancePlugin.instance.server.rconCommandResults.set("b", { time: 50, response: "b" });
|
||||
|
||||
let a = instancePlugin.sendOrderedRcon("a");
|
||||
let b = instancePlugin.sendOrderedRcon("b");
|
||||
let result = await Promise.race([a, b]);
|
||||
assert.equal(result, "a");
|
||||
});
|
||||
it("should propagate errors", async function() {
|
||||
instancePlugin.instance.server.rconCommandResults.set("a", new Error("ref"));
|
||||
await assert.rejects(instancePlugin.sendOrderedRcon("a"), new Error("ref"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("class BaseMasterPlugin", function() {
|
||||
|
||||
Reference in new issue
Block a user