diff --git a/server/src/external/redis/redis-IPC.test.ts b/server/src/external/redis/redis-IPC.test.ts deleted file mode 100644 index 118256808..000000000 --- a/server/src/external/redis/redis-IPC.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { RedisPub, RedisSub } from "./redis-IPC"; -import t from "tap"; - -/** - * Note: The functions these things use have been stubbed out. However, the tests still run and - * they also still work. We'll skip them though, anyway. - */ - -t.skip("Basic PUB/SUB testing", (t) => { - t.setTimeout(2000); - RedisSub("test" as any, (d) => { - t.equal(d.userID, 1); - t.pass(); - t.end(); - }); - - RedisPub("test" as any, { userID: 1 } as any); -}); diff --git a/server/src/external/redis/redis-IPC.ts b/server/src/external/redis/redis-IPC.ts deleted file mode 100644 index 2d2bc2fe9..000000000 --- a/server/src/external/redis/redis-IPC.ts +++ /dev/null @@ -1,99 +0,0 @@ -import CreateLogCtx from "lib/logger/logger"; -import { TachiConfig } from "lib/setup/config"; -import redis from "redis"; - -/** - * This code has been stubbed out! It doesn't really have a use at the moment. - * At some point, though, we might actually need this. (Maybe for a logging framework) - * - * This was used to communicate with other processes running on the same host as this server. - * The idea was the use it for the discord bot, however, we have webhooks now that do this (better). - * Thanks! - */ - -const logger = CreateLogCtx(__filename); - -// Stub types. In the future, we may actually use this. -export type RedisIPCChannels = ""; -export interface RedisIPCData { - "": unknown; -} - -type RedisSubCallback = (data: RedisIPCData[T]) => void; - -type SubCallbacksType = { - [K in RedisIPCChannels]: Array>; -}; - -const SubCallbacks: Partial = {}; - -// Redis doesn't allow one client to subscribe and publish -// There's little to no overhead to having these three clients, -// so - that's why its like this. -const SubClient = redis.createClient(); -const PubClient = redis.createClient(); - -const PREFIX = TachiConfig.NAME.toUpperCase(); - -export function RedisPub(channel: T, data: RedisIPCData[T]) { - PubClient.publish(`${PREFIX}-${channel}`, JSON.stringify(data)); -} - -export function RedisSub(channel: T, callback: RedisSubCallback) { - if (SubCallbacks[channel]) { - SubCallbacks[channel]!.push(callback); - logger.debug(`Pushed callback ${callback.name} to channel ${channel}.`); - } else { - // @ts-expect-error see above. - SubCallbacks[channel] = [callback]; - SubClient.subscribe(`${PREFIX}-${channel}`); - logger.debug(`Added first callback ${callback.name} to channel ${channel}.`); - } -} - -SubClient.on("message", (channel, strData) => { - if (!channel.startsWith(`${PREFIX}-`)) { - // not our business - return; - } - - const ktChannel = channel.slice(`${PREFIX}-`.length) as RedisIPCChannels; - - if (!Object.prototype.hasOwnProperty.call(SubCallbacks, ktChannel)) { - // no callbacks to call - return; - } - - const jsData = JSON.parse(strData) as unknown; - - for (const cb of SubCallbacks[ktChannel]!) { - try { - cb(jsData); - } catch (err) { - logger.error(`Error calling callback ${cb.name} for channel ${ktChannel}`, { err }); - } - } -}); - -// Awful... -// Function is near-impossible to test. -/* istanbul ignore next */ -export function CloseRedisPubSub() { - return new Promise((resolve, reject) => { - PubClient.quit((err: unknown) => { - if (err !== null && err !== undefined) { - logger.crit(`PubClient QUIT error`, { err }); - reject(err); - } - - SubClient.quit((err: unknown) => { - if (err !== null && err !== undefined) { - logger.crit(`SubClient QUIT error`, { err }); - reject(err); - } - - resolve(); - }); - }); - }); -} diff --git a/server/src/test-utils/cleanup.ts b/server/src/test-utils/cleanup.ts index 4fed67c1e..6b9b4716c 100644 --- a/server/src/test-utils/cleanup.ts +++ b/server/src/test-utils/cleanup.ts @@ -2,7 +2,6 @@ import { CloseServerConnection } from "./mock-api"; import { WriteSnapshotData } from "./single-process-snapshot"; import { CloseMongoConnection } from "external/mongo/db"; import { CloseRedisConnection } from "external/redis/redis"; -import { CloseRedisPubSub } from "external/redis/redis-IPC"; import { CloseScoreImportQueue } from "lib/score-import/worker/queue"; export async function CleanUpAfterTests() { @@ -13,6 +12,5 @@ export async function CleanUpAfterTests() { await CloseMongoConnection(); await CloseServerConnection(); await CloseRedisConnection(); - await CloseRedisPubSub(); await CloseScoreImportQueue(); }