tests are succeeding

This commit is contained in:
Skillz4Killz
2021-04-08 21:18:01 +00:00
committed by GitHub
parent 34b3a1b271
commit 417ec0400d
12 changed files with 28 additions and 38 deletions
+1 -2
View File
@@ -15,7 +15,6 @@ jobs:
run: deno cache --no-check mod.ts run: deno cache --no-check mod.ts
- name: Run test script - name: Run test script
if: github.ref == 'refs/heads/main' if: github.ref == 'refs/heads/main'
# run: deno test --allow-net --allow-env run: deno test --allow-net --allow-env --no-check
run: deno test --no-check -A $(find -name "*.ts")
env: env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
-1
View File
@@ -8,7 +8,6 @@ export async function processQueue(id: string) {
if (!queue) return; if (!queue) return;
while (queue.length) { while (queue.length) {
console.log("process queue");
// IF THE BOT IS GLOBALLY RATELIMITED TRY AGAIN // IF THE BOT IS GLOBALLY RATELIMITED TRY AGAIN
if (rest.globallyRateLimited) { if (rest.globallyRateLimited) {
setTimeout(() => processQueue(id), 1000); setTimeout(() => processQueue(id), 1000);
-2
View File
@@ -4,10 +4,8 @@ import { ws } from "./ws.ts";
/** The handler to clean up shards that identified but never received a READY. */ /** The handler to clean up shards that identified but never received a READY. */
export async function cleanupLoadingShards() { export async function cleanupLoadingShards() {
while (ws.loadingShards.size) { while (ws.loadingShards.size) {
console.log("cls");
const now = Date.now(); const now = Date.now();
ws.loadingShards.forEach((loadingShard) => { ws.loadingShards.forEach((loadingShard) => {
console.log(loadingShard);
// Not a minute yet. Max should be few seconds but do a minute to be safe. // Not a minute yet. Max should be few seconds but do a minute to be safe.
if (now < loadingShard.startedAt + 60000) return; if (now < loadingShard.startedAt + 60000) return;
+12 -1
View File
@@ -16,9 +16,20 @@ export async function createShard(shardId: number) {
socket.onclose = (event) => { socket.onclose = (event) => {
ws.log("CLOSED", { shardId, payload: 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 }); 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? // TODO: ENUM FOR THESE CODES?
switch (event.code) { switch (event.code) {
-12
View File
@@ -78,20 +78,8 @@ export async function handleOnMessage(message: any, shardId: number) {
shard.sessionId = (messageData.d as DiscordReady).session_id; 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.get(shardId)?.resolve(true);
ws.loadingShards.delete(shardId); ws.loadingShards.delete(shardId);
console.log(
"shoulda deleted it",
shardId,
ws.loadingShards.has(shardId),
ws.loadingShards
);
} }
// Update the sequence number if it is present // Update the sequence number if it is present
-1
View File
@@ -37,7 +37,6 @@ export async function identify(shardId: number, maxShards: number) {
}; };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log("setting the shard loader");
ws.loadingShards.set(shardId, { ws.loadingShards.set(shardId, {
shardId, shardId,
resolve, resolve,
+1 -1
View File
@@ -4,7 +4,7 @@ import { ws } from "./ws.ts";
/** The handler to automatically reshard when necessary. */ /** The handler to automatically reshard when necessary. */
export async function resharder() { export async function resharder() {
const data = await getGatewayBot(); 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 // Less than necessary% being used so do nothing
if (percentage < ws.reshardPercentage) return; if (percentage < ws.reshardPercentage) return;
-1
View File
@@ -44,7 +44,6 @@ export function spawnShards(firstShardId = 0) {
let shardId = queue.shift(); let shardId = queue.shift();
while (shardId !== undefined) { while (shardId !== undefined) {
console.log("spawn shards");
await ws.tellClusterToIdentify(clusterId as number, shardId, bucketId); await ws.tellClusterToIdentify(clusterId as number, shardId, bucketId);
shardId = queue.shift(); shardId = queue.shift();
} }
+3 -7
View File
@@ -22,13 +22,9 @@ export async function startGateway(options: StartGatewayOptions) {
// setInterval(ws.resharder, 1000 * 60 * 60); // setInterval(ws.resharder, 1000 * 60 * 60);
ws.identifyPayload.intents = options.intents.reduce( ws.identifyPayload.intents = options.intents.reduce(
( (bits, next) =>
bits, (bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
next, 0
) => (bits |= typeof next === "string"
? DiscordGatewayIntents[next]
: next),
0,
); );
const data = (await fetch(`https://discord.com/api/gateway/bot`, { const data = (await fetch(`https://discord.com/api/gateway/bot`, {
+1 -2
View File
@@ -4,11 +4,10 @@ import { ws } from "./ws.ts";
export async function tellClusterToIdentify( export async function tellClusterToIdentify(
workerId: number, workerId: number,
shardId: number, shardId: number,
bucketId: number, bucketId: number
) { ) {
// When resharding this may exist already // When resharding this may exist already
const oldShard = ws.shards.get(shardId); const oldShard = ws.shards.get(shardId);
// TODO: Use workers // TODO: Use workers
await ws.identify(shardId, ws.maxShards); await ws.identify(shardId, ws.maxShards);
+10 -8
View File
@@ -3,16 +3,16 @@ import { assertExists } from "./deps.ts";
// Set necessary settings // Set necessary settings
// Disables the logger which logs everything // Disables the logger which logs everything
ws.log = function (x: string, d: any) { ws.log = function (_x: string, _d: unknown) {
if (["RAW", "GUILD_CREATE", "HEARTBEATING_DETAILS"].includes(x)) return console.log(x); // if (["RAW", "GUILD_CREATE", "HEARTBEATING_DETAILS"].includes(_x))
console.log(x, d); // return console.log(_x);
// console.log(_x, _d);
}; };
// Default options for tests // Default options for tests
export const defaultTestOptions: Partial<Deno.TestDefinition> = { export const defaultTestOptions: Partial<Deno.TestDefinition> = {
sanitizeOps: false, sanitizeOps: false,
sanitizeResources: false, sanitizeResources: false,
sanitizeExit: false,
}; };
// Temporary data // Temporary data
@@ -311,14 +311,16 @@ Deno.test({
// ...defaultTestOptions, // ...defaultTestOptions,
// }); // });
// Forcefully exit the Deno process once all tests are done. // Exit the Deno process once all tests are done.
Deno.test({ Deno.test({
name: "[main] exit the process forcefully", name: "[main] Close all shards manually.",
fn() { async fn() {
ws.shards.forEach((shard) => { ws.shards.forEach((shard) => {
clearInterval(shard.heartbeat.intervalId); clearInterval(shard.heartbeat.intervalId);
shard.ws.close(); shard.ws.close(3064, "Discordeno Testing Finished! Do Not RESUME!");
}); });
await delay(3000);
}, },
...defaultTestOptions, ...defaultTestOptions,
}); });