Skip to content

Commit

Permalink
fix: hanging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Oct 31, 2024
1 parent 39c885a commit 99b75b9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 10 additions & 4 deletions packages/data-flow/src/orchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// class should contain the logic to orchestrate the data flow Events Fetcher -> Events Processor -> Data Loader

import { IIndexerClient } from "@grants-stack-indexer/indexer-client";
import {
existsHandler,
Expand Down Expand Up @@ -62,6 +60,14 @@ export class Orchestrator {
private readonly strategyRegistry: IStrategyRegistry;
private readonly dataLoader: DataLoader;

/**
* @param chainId - The chain id
* @param dependencies - The core dependencies
* @param indexerClient - The indexer client
* @param registries - The registries
* @param fetchLimit - The fetch limit
* @param fetchDelayInMs - The fetch delay in milliseconds
*/
constructor(
private chainId: ChainId,
private dependencies: Readonly<CoreDependencies>,
Expand All @@ -71,7 +77,7 @@ export class Orchestrator {
strategyRegistry: IStrategyRegistry;
},
private fetchLimit: number = 1000,
private fetchDelay: number = 10000,
private fetchDelayInMs: number = 10000,
) {
this.eventsFetcher = new EventsFetcher(this.indexerClient);
this.eventsProcessor = new EventsProcessor(this.chainId, this.dependencies);
Expand All @@ -95,7 +101,7 @@ export class Orchestrator {
event = this.eventsQueue.pop();

if (!event) {
await delay(this.fetchDelay);
await delay(this.fetchDelayInMs);
continue;
}

Expand Down
11 changes: 7 additions & 4 deletions packages/data-flow/test/unit/orchestrator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address } from "viem";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";

import { EvmProvider } from "@grants-stack-indexer/chain-providers";
import { IIndexerClient } from "@grants-stack-indexer/indexer-client";
Expand Down Expand Up @@ -91,9 +91,6 @@ describe("Orchestrator", { sequential: true }, () => {
},
};

// vi.mocked(EventsProcessor).mockImplementation(() => mockEventsProcessor);
// vi.mocked(DataLoader).mockImplementation(() => mockDataLoader);

orchestrator = new Orchestrator(
chainId,
dependencies,
Expand All @@ -107,6 +104,12 @@ describe("Orchestrator", { sequential: true }, () => {
);
});

afterAll(() => {
vi.clearAllMocks();

return new Promise((resolve) => setImmediate(resolve));
});

describe("Event Processing Flow", () => {
it("process events in the correct order", async () => {
const mockEvents = [
Expand Down

0 comments on commit 99b75b9

Please sign in to comment.