diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 448b1563e..7be569400 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,6 @@ jobs: run: deno cache --no-check mod.ts - name: Run test script if: github.ref == 'refs/heads/main' - # run: deno test --allow-net --allow-env - run: deno test --no-check -A $(find -name "*.ts") + run: deno test --allow-net --allow-env --no-check env: DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} diff --git a/src/rest/process_queue.ts b/src/rest/process_queue.ts index 77f3cc863..b9539da1c 100644 --- a/src/rest/process_queue.ts +++ b/src/rest/process_queue.ts @@ -8,7 +8,6 @@ export async function processQueue(id: string) { if (!queue) return; while (queue.length) { - console.log("process queue"); // IF THE BOT IS GLOBALLY RATELIMITED TRY AGAIN if (rest.globallyRateLimited) { setTimeout(() => processQueue(id), 1000); diff --git a/src/ws/cleanup_loading_shards.ts b/src/ws/cleanup_loading_shards.ts index 10bc8fe22..af2acf387 100644 --- a/src/ws/cleanup_loading_shards.ts +++ b/src/ws/cleanup_loading_shards.ts @@ -4,10 +4,8 @@ import { ws } from "./ws.ts"; /** The handler to clean up shards that identified but never received a READY. */ export async function cleanupLoadingShards() { while (ws.loadingShards.size) { - console.log("cls"); const now = Date.now(); ws.loadingShards.forEach((loadingShard) => { - console.log(loadingShard); // Not a minute yet. Max should be few seconds but do a minute to be safe. if (now < loadingShard.startedAt + 60000) return; diff --git a/src/ws/create_shard.ts b/src/ws/create_shard.ts index 9db9e5a18..8982be351 100644 --- a/src/ws/create_shard.ts +++ b/src/ws/create_shard.ts @@ -16,9 +16,20 @@ export async function createShard(shardId: number) { socket.onclose = (event) => { ws.log("CLOSED", { shardId, payload: event }); - if (event.code === 4009 && ["Resharded!", "Resuming the shard, closing old shard."].includes(event.reason)) { + if ( + event.code === 4009 && + ["Resharded!", "Resuming the shard, closing old shard."].includes( + event.reason + ) + ) { return ws.log("CLOSED_RECONNECT", { shardId, payload: event }); } + if ( + event.code === 3064 || + event.reason === "Discordeno Testing Finished! Do Not RESUME!" + ) { + return; + } // TODO: ENUM FOR THESE CODES? switch (event.code) { diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index faeb856bf..1a202fd75 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -78,20 +78,8 @@ export async function handleOnMessage(message: any, shardId: number) { shard.sessionId = (messageData.d as DiscordReady).session_id; } - console.log( - "shoulda deleted it", - shardId, - ws.loadingShards.has(shardId), - ws.loadingShards - ); ws.loadingShards.get(shardId)?.resolve(true); ws.loadingShards.delete(shardId); - console.log( - "shoulda deleted it", - shardId, - ws.loadingShards.has(shardId), - ws.loadingShards - ); } // Update the sequence number if it is present diff --git a/src/ws/identify.ts b/src/ws/identify.ts index 479b73249..90ae0da23 100644 --- a/src/ws/identify.ts +++ b/src/ws/identify.ts @@ -37,7 +37,6 @@ export async function identify(shardId: number, maxShards: number) { }; return new Promise((resolve, reject) => { - console.log("setting the shard loader"); ws.loadingShards.set(shardId, { shardId, resolve, diff --git a/src/ws/resharder.ts b/src/ws/resharder.ts index 25e81d7dd..93ee219ab 100644 --- a/src/ws/resharder.ts +++ b/src/ws/resharder.ts @@ -4,7 +4,7 @@ import { ws } from "./ws.ts"; /** The handler to automatically reshard when necessary. */ export async function resharder() { const data = await getGatewayBot(); - const percentage = (data.shards - ws.maxShards) / ws.maxShards * 100; + const percentage = ((data.shards - ws.maxShards) / ws.maxShards) * 100; // Less than necessary% being used so do nothing if (percentage < ws.reshardPercentage) return; diff --git a/src/ws/spawn_shards.ts b/src/ws/spawn_shards.ts index 2f9aad59d..4fff000aa 100644 --- a/src/ws/spawn_shards.ts +++ b/src/ws/spawn_shards.ts @@ -44,7 +44,6 @@ export function spawnShards(firstShardId = 0) { let shardId = queue.shift(); while (shardId !== undefined) { - console.log("spawn shards"); await ws.tellClusterToIdentify(clusterId as number, shardId, bucketId); shardId = queue.shift(); } diff --git a/src/ws/start_gateway.ts b/src/ws/start_gateway.ts index 90ab27670..afb51f02f 100644 --- a/src/ws/start_gateway.ts +++ b/src/ws/start_gateway.ts @@ -22,13 +22,9 @@ export async function startGateway(options: StartGatewayOptions) { // setInterval(ws.resharder, 1000 * 60 * 60); ws.identifyPayload.intents = options.intents.reduce( - ( - bits, - next, - ) => (bits |= typeof next === "string" - ? DiscordGatewayIntents[next] - : next), - 0, + (bits, next) => + (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next), + 0 ); const data = (await fetch(`https://discord.com/api/gateway/bot`, { diff --git a/src/ws/tell_cluster_to_identify.ts b/src/ws/tell_cluster_to_identify.ts index 99fc044ce..a801270a3 100644 --- a/src/ws/tell_cluster_to_identify.ts +++ b/src/ws/tell_cluster_to_identify.ts @@ -4,11 +4,10 @@ import { ws } from "./ws.ts"; export async function tellClusterToIdentify( workerId: number, shardId: number, - bucketId: number, + bucketId: number ) { // When resharding this may exist already const oldShard = ws.shards.get(shardId); - // TODO: Use workers await ws.identify(shardId, ws.maxShards); diff --git a/test/mod.ts b/test/mod.test.ts similarity index 95% rename from test/mod.ts rename to test/mod.test.ts index 4fedaf320..0ff2f5b47 100644 --- a/test/mod.ts +++ b/test/mod.test.ts @@ -3,16 +3,16 @@ import { assertExists } from "./deps.ts"; // Set necessary settings // Disables the logger which logs everything -ws.log = function (x: string, d: any) { - if (["RAW", "GUILD_CREATE", "HEARTBEATING_DETAILS"].includes(x)) return console.log(x); - console.log(x, d); +ws.log = function (_x: string, _d: unknown) { + // if (["RAW", "GUILD_CREATE", "HEARTBEATING_DETAILS"].includes(_x)) + // return console.log(_x); + // console.log(_x, _d); }; // Default options for tests export const defaultTestOptions: Partial = { sanitizeOps: false, sanitizeResources: false, - sanitizeExit: false, }; // Temporary data @@ -311,14 +311,16 @@ Deno.test({ // ...defaultTestOptions, // }); -// Forcefully exit the Deno process once all tests are done. +// Exit the Deno process once all tests are done. Deno.test({ - name: "[main] exit the process forcefully", - fn() { + name: "[main] Close all shards manually.", + async fn() { ws.shards.forEach((shard) => { clearInterval(shard.heartbeat.intervalId); - shard.ws.close(); + shard.ws.close(3064, "Discordeno Testing Finished! Do Not RESUME!"); }); + + await delay(3000); }, ...defaultTestOptions, }); diff --git a/test/util/utils.ts b/test/util/utils.test.ts similarity index 100% rename from test/util/utils.ts rename to test/util/utils.test.ts