Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with error handling in task waiter #127

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/features/serverTasks/serverTaskWaiter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Client } from "../../client";
import { processConfiguration } from "../../clientConfiguration.test";
import { ServerTaskDetails } from "./serverTaskDetails";
import { ServerTaskWaiter } from "./serverTaskWaiter";

describe("push build information", () => {
jest.setTimeout(100000);

test("wait for non-existent task exits correctly", async () => {
const client = await Client.create(processConfiguration());
const serverTaskWaiter = new ServerTaskWaiter(client, "Default");

const startTime = new Date();

await expect(() => {
return serverTaskWaiter.waitForServerTaskToComplete("ServerTasks-99999", 1000, 10000);
}).rejects.toThrow();

const endTime = new Date();
const timeDiff = endTime.getTime() - startTime.getTime();
expect(timeDiff).toBeLessThan(6000);
});
});
26 changes: 14 additions & 12 deletions src/features/serverTasks/serverTaskWaiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ export class ServerTaskWaiter {
}, timeout);

while (!stop) {
if (pollingCallback) {
const taskDetails = await spaceServerTaskRepository.getDetails(serverTaskId);
pollingCallback(taskDetails);
try {
if (pollingCallback) {
const taskDetails = await spaceServerTaskRepository.getDetails(serverTaskId);
pollingCallback(taskDetails);

if (taskDetails.Task.IsCompleted) {
clearTimeout(t);
return taskDetails.Task;
}
} else {
const task = await spaceServerTaskRepository.getById(serverTaskId);
if (taskDetails.Task.IsCompleted) {
return taskDetails.Task;
}
} else {
const task = await spaceServerTaskRepository.getById(serverTaskId);

if (task.IsCompleted) {
clearTimeout(t);
return task;
if (task.IsCompleted) {
return task;
}
}
} finally {
clearTimeout(t);
}

await sleep(statusCheckSleepCycle);
Expand Down