-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' into feature/JST-516
- Loading branch information
Showing
15 changed files
with
274 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { MarketService } from "../market/"; | ||
import { AgreementPoolService } from "../agreement/"; | ||
import { TaskService } from "../task/"; | ||
import { TaskExecutor } from "./executor"; | ||
import { sleep } from "../utils"; | ||
import { LoggerMock } from "../../tests/mock"; | ||
|
||
jest.mock("../market/service"); | ||
jest.mock("../agreement/service"); | ||
jest.mock("../network/service"); | ||
jest.mock("../task/service"); | ||
jest.mock("../storage/gftp"); | ||
jest.mock("../utils/yagna/yagna"); | ||
|
||
const serviceRunSpy = jest.fn().mockImplementation(() => Promise.resolve()); | ||
jest.spyOn(MarketService.prototype, "run").mockImplementation(serviceRunSpy); | ||
jest.spyOn(AgreementPoolService.prototype, "run").mockImplementation(serviceRunSpy); | ||
jest.spyOn(TaskService.prototype, "run").mockImplementation(serviceRunSpy); | ||
|
||
jest.mock("../payment/service", () => { | ||
return { | ||
PaymentService: jest.fn().mockImplementation(() => { | ||
return { | ||
config: { payment: { network: "test" } }, | ||
createAllocation: jest.fn(), | ||
run: serviceRunSpy, | ||
end: jest.fn(), | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
describe("Task Executor", () => { | ||
const logger = new LoggerMock(); | ||
const yagnaOptions = { apiKey: "test" }; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
logger.clear(); | ||
}); | ||
|
||
describe("init()", () => { | ||
it("should run all set services", async () => { | ||
const executor = await TaskExecutor.create({ package: "test", logger, yagnaOptions }); | ||
expect(serviceRunSpy).toHaveBeenCalledTimes(4); | ||
expect(executor).toBeDefined(); | ||
await executor.end(); | ||
}); | ||
it("should handle a critical error if startup timeout is reached", async () => { | ||
const executor = await TaskExecutor.create({ package: "test", startupTimeout: 0, logger, yagnaOptions }); | ||
jest | ||
.spyOn(MarketService.prototype, "getProposalsCount") | ||
.mockImplementation(() => ({ confirmed: 0, initial: 0, rejected: 0 })); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const handleErrorSpy = jest.spyOn(executor as any, "handleCriticalError").mockImplementation((error) => { | ||
expect((error as Error).message).toEqual( | ||
"Could not start any work on Golem. Processed 0 initial proposals from yagna, filters accepted 0. Check your demand if it's not too restrictive or restart yagna.", | ||
); | ||
}); | ||
await sleep(10, true); | ||
expect(handleErrorSpy).toHaveBeenCalled(); | ||
await executor.end(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.