Skip to content

Commit

Permalink
test(work_context): unit and e2e tests for streaming results
Browse files Browse the repository at this point in the history
  • Loading branch information
mgordel committed Oct 30, 2023
1 parent 8201d33 commit ffcddc1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/task/work.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ describe("Work Context", () => {
});
});

describe("runAndStream()", () => {
it("should execute runAndStream command", async () => {
const expectedResult = ActivityMock.createResult({ stdout: "Ok" });
activity.mockResults([expectedResult]);
const streamOfResults = await context.runAndStream("rm -rf");
for await (const result of streamOfResults) {
expect(result).toBe(expectedResult);
}
});
});

describe("transfer()", () => {
it("should execute transfer command", async () => {
const result = ActivityMock.createResult({ stdout: "Ok" });
Expand Down
19 changes: 19 additions & 0 deletions tests/e2e/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,23 @@ describe("Task Executor", function () {
const result = await executor.run(async (ctx) => ctx.getIp());
expect(["192.168.0.2", "192.168.0.3"]).toContain(result);
});

it("should run simple task and get results as stream", async () => {
executor = await TaskExecutor.create({
package: "golem/alpine:latest",
logger,
});
const streamOfResults = await executor.run(async (ctx) => ctx.runAndStream("echo 'Hello World'"));
expect(streamOfResults).toBeDefined();
for await (const result of streamOfResults!) {
expect(result.stdout).toContain("Hello World");
expect(result.result).toContain("Ok");
}
expect(logger.logs).toContain("Demand published on the market");
expect(logger.logs).toContain("New proposal has been received");
expect(logger.logs).toContain("Proposal has been responded");
expect(logger.logs).toContain("New proposal added to pool");
expect(logger.logs).toMatch(/Agreement confirmed by provider/);
expect(logger.logs).toMatch(/Activity .* created/);
});
});

0 comments on commit ffcddc1

Please sign in to comment.