From ceb0b217190f467dc9abd1ee4a1f68cd0750f002 Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 11 Sep 2026 16:06:44 -0500 Subject: [PATCH] test: wait for active Daytona transfers before teardown Co-Authored-By: Paperclip --- .../sandbox-providers/daytona/src/plugin.test.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts b/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts index 84787dff01..a4699bcad0 100644 --- a/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts +++ b/packages/plugins/sandbox-providers/daytona/src/plugin.test.ts @@ -4830,15 +4830,21 @@ describe("daytona native file-sync hooks", () => { // Hold the inbound upload and the outbound download open at the same time, so // the shared lease has two active sync calls when teardown starts. let releaseUpload!: () => void; + let uploadStarted!: () => void; + const uploadReady = new Promise((resolve) => { uploadStarted = resolve; }); sandbox.fs.uploadFiles.mockImplementation(async () => { await new Promise((resolve) => { releaseUpload = resolve; + uploadStarted(); }); }); let releaseDownload!: () => void; + let downloadStarted!: () => void; + const downloadReady = new Promise((resolve) => { downloadStarted = resolve; }); sandbox.fs.downloadFiles.mockImplementation(async (requests: Array<{ source: string; destination: string }>) => { await new Promise((resolve) => { releaseDownload = resolve; + downloadStarted(); }); return Promise.all( requests.map(async (request) => { @@ -4855,9 +4861,9 @@ describe("daytona native file-sync hooks", () => { const outboundCall = plugin.definition.onEnvironmentSyncOut?.( syncOutParams({ operationId: "out-active", sourcePath: `${REMOTE_DIR}/out.txt`, targetPath: outboundTarget }), ); - // Let both sync calls register on the activity gate and reach their hung - // transfer, so teardown sees a refCount of two. - await new Promise((resolve) => setTimeout(resolve, 0)); + // Wait for both actual transfers, rather than assuming one event-loop tick + // completes the asynchronous filesystem preparation on a busy runner. + await Promise.all([uploadReady, downloadReady]); const destroyCall = plugin.definition.onEnvironmentDestroyLease?.({ driverKey: "daytona",