Skip to content

Commit 98c1e0c

Browse files
committed
update wait job to finish test
1 parent 01b6c1a commit 98c1e0c

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

test/compute.test.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,35 @@ describe("Ocean CLI Free Compute Flow", function () {
147147
`npm run cli getJobStatus --dataset ${datasetDid} --job ${jobId}`
148148
);
149149
console.log(`Job status cmd output : ${output}`);
150-
if (/status:\s*Job finished/i.test(output)) {
151-
return;
150+
151+
const jsonMatch = output.match(/\[\s*{[\s\S]*}\s*\]/);
152+
if (!jsonMatch) {
153+
console.warn("Could not find JSON array in output, will retry...");
154+
await new Promise((res) => setTimeout(res, pollIntervalMs));
155+
continue;
156+
}
157+
158+
let jobs;
159+
try {
160+
jobs = JSON.parse(jsonMatch[0]);
161+
} catch (e) {
162+
console.warn("Failed to parse job status JSON, will retry...");
163+
await new Promise((res) => setTimeout(res, pollIntervalMs));
164+
continue;
165+
}
166+
167+
if (Array.isArray(jobs) && jobs.length > 0) {
168+
const job = jobs[0];
169+
if (
170+
(typeof job.statusText === "string" &&
171+
job.statusText.toLowerCase().includes("finished")) ||
172+
job.status === 70
173+
) {
174+
console.log("Job is finished!");
175+
return job;
176+
}
152177
}
178+
153179
await new Promise((res) => setTimeout(res, pollIntervalMs));
154180
}
155181
throw new Error(
@@ -158,17 +184,26 @@ describe("Ocean CLI Free Compute Flow", function () {
158184
};
159185

160186
it("should download compute job results", async () => {
161-
await waitForJobCompletion(computeDatasetDid, jobId, 180000, 7000);
187+
// Wait for job to finish and get job details
188+
const job = await waitForJobCompletion(
189+
computeDatasetDid,
190+
jobId,
191+
180000,
192+
7000
193+
);
194+
console.log("Job details:", job);
162195

163196
const destFolder = path.join(projectRoot, "test-results", jobId);
164197
fs.mkdirSync(destFolder, { recursive: true });
165198

166199
const output = await runCommand(
167-
`npm run cli downloadJobResults ${jobId} 0 ${destFolder}`
200+
`npm run cli downloadJobResults ${jobId} 1 ${destFolder}`
168201
);
169202

170-
console.log(`Download job results cmd output: ${output}`);
171-
172203
expect(output.toLowerCase()).to.match(/download(ed)?/);
204+
205+
// const files = fs.readdirSync(destFolder);
206+
// expect(files.length).to.be.greaterThan(0, "No result files downloaded");
207+
// console.log(`Downloaded results to: ${destFolder}`);
173208
});
174209
});

0 commit comments

Comments
 (0)