mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
tests are succeeding
This commit is contained in:
@@ -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 }}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+12
-1
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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`, {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<Deno.TestDefinition> = {
|
||||
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,
|
||||
});
|
||||
Reference in New Issue
Block a user