-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: implement general setup and teardown hooks for bullmq queues
- Loading branch information
Showing
21 changed files
with
161 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { afterAll, beforeEach } from "vitest"; | ||
|
||
import { queueManager } from "./src/queue-manager"; | ||
|
||
beforeEach(async () => { | ||
await queueManager.obliterateQueues({ force: true }); | ||
}); | ||
afterAll(async () => { | ||
await queueManager | ||
.obliterateQueues({ force: true }) | ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
.finally(() => queueManager.close()); | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*.ts", "test/**/*.ts", "vitest.config.ts"] | ||
"include": ["src/**/*.ts", "test/**/*.ts", "vitest.config.ts", "setup.ts"] | ||
} |
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { defineProject } from "vitest/config"; | ||
import { defineConfig, mergeConfig } from "vitest/config"; | ||
|
||
export default defineProject({ | ||
test: { | ||
include: ["test/**/*.test.ts"], | ||
threads: false, | ||
}, | ||
}); | ||
import { sharedProjectConfig } from "../../vitest.shared"; | ||
|
||
export default mergeConfig( | ||
sharedProjectConfig, | ||
defineConfig({ | ||
test: { | ||
setupFiles: ["./setup.ts"], | ||
}, | ||
}) | ||
); |
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,36 @@ | ||
import { Queue } from "bullmq"; | ||
import type { RedisOptions } from "ioredis"; | ||
import { afterAll } from "vitest"; | ||
|
||
import { blobFileManager } from "./src/blob-file-manager"; | ||
import { env } from "./src/env"; | ||
import { FINALIZER_WORKER_NAME, STORAGE_WORKER_NAMES } from "./src/utils"; | ||
|
||
const connection: RedisOptions = { | ||
host: env.REDIS_QUEUE_HOST, | ||
port: env.REDIS_QUEUE_PORT, | ||
password: env.REDIS_QUEUE_PASSWORD, | ||
username: env.REDIS_QUEUE_USERNAME, | ||
}; | ||
|
||
afterAll(async () => { | ||
const queues = [ | ||
STORAGE_WORKER_NAMES["GOOGLE"], | ||
STORAGE_WORKER_NAMES["POSTGRES"], | ||
FINALIZER_WORKER_NAME, | ||
].map((queueName) => new Queue(queueName, { connection })); | ||
|
||
let teardownPromise = Promise.all([ | ||
...queues.map((q) => q.obliterate({ force: true })), | ||
blobFileManager.removeFolder(), | ||
]); | ||
|
||
queues.forEach((q) => { | ||
// eslint-disable-next-line @typescript-eslint/no-misused-promises | ||
teardownPromise = teardownPromise.finally(async () => { | ||
await q.close(); | ||
}); | ||
}); | ||
|
||
await teardownPromise; | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { getBlobStorageManager } from "@blobscan/blob-storage-manager"; | ||
|
||
import type { BlobPropagationWorkerProcessor } from "../types"; | ||
import { propagateBlob } from "../utils"; | ||
|
||
export const gcsProcessor: BlobPropagationWorkerProcessor = (job) => { | ||
return propagateBlob(job.data.versionedHash, "GOOGLE"); | ||
export const gcsProcessor: BlobPropagationWorkerProcessor = async (job) => { | ||
const blobStorageManager = await getBlobStorageManager(); | ||
|
||
return propagateBlob(job.data.versionedHash, "GOOGLE", { | ||
blobStorageManager, | ||
}); | ||
}; |
12 changes: 10 additions & 2 deletions
12
packages/blob-propagator/src/worker-processors/postgres.ts
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import { getBlobStorageManager } from "@blobscan/blob-storage-manager"; | ||
|
||
import type { BlobPropagationWorkerProcessor } from "../types"; | ||
import { propagateBlob } from "../utils"; | ||
|
||
export const postgresProcessor: BlobPropagationWorkerProcessor = (job) => { | ||
return propagateBlob(job.data.versionedHash, "POSTGRES"); | ||
export const postgresProcessor: BlobPropagationWorkerProcessor = async ( | ||
job | ||
) => { | ||
const blobStorageManager = await getBlobStorageManager(); | ||
|
||
return propagateBlob(job.data.versionedHash, "POSTGRES", { | ||
blobStorageManager, | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import { getBlobStorageManager } from "@blobscan/blob-storage-manager"; | ||
|
||
import type { BlobPropagationWorkerProcessor } from "../types"; | ||
import { propagateBlob } from "../utils"; | ||
|
||
export const swarmProcessor: BlobPropagationWorkerProcessor = function (job) { | ||
return propagateBlob(job.data.versionedHash, "SWARM"); | ||
export const swarmProcessor: BlobPropagationWorkerProcessor = async function ( | ||
job | ||
) { | ||
const blobStorageManager = await getBlobStorageManager(); | ||
|
||
return propagateBlob(job.data.versionedHash, "SWARM", { blobStorageManager }); | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*.ts", "test/**/*.ts", "vitest.config.ts"] | ||
"include": ["src/**/*.ts", "test/**/*.ts", "vitest.config.ts", "setup.ts"] | ||
} |
Oops, something went wrong.