diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index ce6b8099..0a34f6b3 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -92,6 +92,16 @@ async function uploadSave(instanceId, name, content) { }); } +async function waitForFileExists(filePath, timeoutMs = 5000) { + const start = Date.now(); + while (!(await fs.pathExists(filePath))) { + if (Date.now() - start > timeoutMs) { + throw new Error(`Timed out waiting for file ${filePath}`); + } + await new Promise(resolve => setTimeout(resolve, 100)); + } +} + async function deleteSave(instanceId, save) { await getControl().send(new lib.InstanceDeleteSaveRequest(instanceId, save)); } @@ -1055,13 +1065,13 @@ describe("Integration of Clusterio", function() { describe("instance save transfer", function() { before(async function() { slowTest(this); - await execCtl("instance create spam --id 66"); - await execCtl("instance assign spam 4"); - await execCtl("instance create unassign --id 77"); + await execCtlProcess("instance create spam --id 66"); + await execCtlProcess("instance assign spam 4"); + await execCtlProcess("instance create unassign --id 77"); }); after(async function() { try { - await execCtl("instance delete spam"); + await execCtlProcess("instance delete spam"); } catch (err) { // Ignore } @@ -1075,14 +1085,16 @@ describe("Integration of Clusterio", function() { : path.join("temp", "test", "instances", "spam", "saves") ; describe(remote ? "remote" : "local", function() { + // Allow extra time for file transfers on slower Node versions + this.timeout(10000); if (remote) { let hostProcess; before(async function() { slowTest(this); hostProcess = await startAltHost(); - await execCtl("instance create save-test --id 88"); - await execCtl("instance assign save-test 5"); + await execCtlProcess("instance create save-test --id 88"); + await execCtlProcess("instance assign save-test 5"); }); after(async function() { await stopAltHost(hostProcess); @@ -1090,14 +1102,16 @@ describe("Integration of Clusterio", function() { } it("should transfers a save", async function() { await uploadSave(pri, "transfer.zip", "transfer.zip"); - await execCtl(`instance save transfer ${pri} transfer.zip ${sec}`); + await execCtlProcess(`instance save transfer ${pri} transfer.zip ${sec}`); + await waitForFileExists(path.join(secSaves, "transfer.zip")); assert(!await fs.pathExists(path.join(priSaves, "transfer.zip")), "save still at pri"); assert(await fs.pathExists(path.join(secSaves, "transfer.zip")), "save not at sec"); await deleteSave(sec, "transfer.zip"); }); it("should support rename", async function() { await uploadSave(pri, "transfer.zip", "transfer.zip"); - await execCtl(`instance save transfer ${pri} transfer.zip ${sec} rename.zip`); + await execCtlProcess(`instance save transfer ${pri} transfer.zip ${sec} rename.zip`); + await waitForFileExists(path.join(secSaves, "rename.zip")); assert(!await fs.pathExists(path.join(priSaves, "transfer.zip")), "save still at pri"); assert(await fs.pathExists(path.join(secSaves, "rename.zip")), "save not at sec"); await deleteSave(sec, "rename.zip"); @@ -1105,15 +1119,18 @@ describe("Integration of Clusterio", function() { it("should auto-rename if target exists", async function() { await uploadSave(pri, "transfer.zip", "transfer.zip"); await uploadSave(sec, "transfer.zip", "transfer.zip"); - await execCtl(`instance save transfer ${pri} transfer.zip ${sec}`); + await execCtlProcess(`instance save transfer ${pri} transfer.zip ${sec}`); + await waitForFileExists(path.join(secSaves, "transfer.zip")); assert(!await fs.pathExists(path.join(priSaves, "transfer.zip")), "save still at pri"); + await waitForFileExists(path.join(secSaves, "transfer-2.zip")); assert(await fs.pathExists(path.join(secSaves, "transfer-2.zip")), "save not at sec"); await deleteSave(sec, "transfer.zip"); await deleteSave(sec, "transfer-2.zip"); }); it("should copy when using --copy", async function() { await uploadSave(pri, "transfer.zip", "transfer.zip"); - await execCtl(`instance save transfer ${pri} transfer.zip ${sec} --copy`); + await execCtlProcess(`instance save transfer ${pri} transfer.zip ${sec} --copy`); + await waitForFileExists(path.join(secSaves, "transfer.zip")); assert(await fs.pathExists(path.join(priSaves, "transfer.zip")), "save not at pri"); assert(await fs.pathExists(path.join(secSaves, "transfer.zip")), "save not at sec"); await deleteSave(pri, "transfer.zip");