Skip to content

Commit

Permalink
Merge branch 'feature/JST-528/streaming-results' into feature/JST-525…
Browse files Browse the repository at this point in the history
…/webrorker-node
  • Loading branch information
mgordel committed Nov 2, 2023
2 parents 7f553b8 + 7f6dacb commit ef6d98a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
11 changes: 5 additions & 6 deletions tests/e2e/tasks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LoggerMock } from "../mock";
import { readFileSync } from "fs";
import { TaskExecutor } from "../../src";
import fs from "fs";
import { Result, TaskExecutor } from "../../src";
const logger = new LoggerMock(false);

describe("Task Executor", function () {
Expand Down Expand Up @@ -186,17 +185,17 @@ describe("Task Executor", function () {
package: "golem/alpine:latest",
logger,
});
const results: Result[] = [];
await executor.run(async (ctx) => {
// for some reason we do not receive events for very simple commands,
// it is probably related to a bug where the command ends and the event does not have time to be triggered or handled
// after creating the EventSource connection to yagna... to investigate.
// for now, sleep 1 has been added, which solves the problem temporarily
const streamOfResults = await ctx.runAndStream("sleep 1 && echo 'Hello World'");
for await (const result of streamOfResults) {
expect(result.stdout).toContain("Hello World");
expect(result.result).toContain("Ok");
}
for await (const result of streamOfResults) results.push(result);
});
expect(results[0].stdout).toContain("Hello World");
expect(results[0].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");
Expand Down
3 changes: 0 additions & 3 deletions tests/mock/rest/yagna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import { Yagna, YagnaApi } from "../../../src/utils";
import { RequestorControlApiMock, RequestorSateApiMock } from "./activity";
import { MarketApiMock } from "./market";
import { EventSourceMock } from "../utils/event_source";
import { PaymentApiMock } from "./payment";
import { NetworkApiMock } from "./network";
import { IdentityApiMock } from "./identity";
import { GsbApiMock } from "./gsb";

jest.mock("eventsource", () => EventSourceMock);

export class YagnaMock extends Yagna {
constructor() {
super({ apiKey: "test_api_key" });
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/activity.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as activityMock from "../mock/rest/activity";
import { setExpectedErrorEvents, setExpectedEvents } from "../mock/utils/event_source";
import { EventSourceMock, setExpectedErrorEvents, setExpectedEvents } from "../mock/utils/event_source";
import { StorageProviderMock, YagnaMock } from "../mock";
import { Activity, ActivityStateEnum } from "../../src/activity";
import { sleep } from "../../src/utils";
import { Deploy, Start, Run, Terminate, UploadFile, DownloadFile, Script, Capture } from "../../src/script";

jest.mock("eventsource", () => EventSourceMock);
describe("Activity", () => {
const yagnaApi = new YagnaMock().getApi();
beforeEach(() => {
Expand Down

0 comments on commit ef6d98a

Please sign in to comment.