mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
Merge branch 'main' into change-enums
This commit is contained in:
75
test.ts
75
test.ts
@@ -1,75 +0,0 @@
|
||||
const config = {
|
||||
maxConcurrency: 16,
|
||||
maxShards: 1120,
|
||||
maxClusters: 140,
|
||||
shardsPerCluster: 8,
|
||||
};
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function organizeClusters() {
|
||||
const clusters = new Map();
|
||||
const buckets = new Map();
|
||||
const shardClusters = new Map<number, number>();
|
||||
let cluster = 0;
|
||||
|
||||
for (let i = 0; i < config.maxShards; i++) {
|
||||
const shards = clusters.get(cluster);
|
||||
if (!shards) clusters.set(cluster, [i]);
|
||||
else {
|
||||
if (shards.length < config.shardsPerCluster) shards.push(i);
|
||||
else {
|
||||
cluster++;
|
||||
clusters.set(cluster, [i]);
|
||||
}
|
||||
}
|
||||
|
||||
shardClusters.set(i, cluster);
|
||||
}
|
||||
|
||||
for (let i = 0; i < config.maxShards; i++) {
|
||||
const bucketID = i % config.maxConcurrency;
|
||||
const bucket = buckets.get(bucketID);
|
||||
if (!bucket) {
|
||||
buckets.set(bucketID, [i]);
|
||||
} else {
|
||||
bucket.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
return { clusters, buckets };
|
||||
}
|
||||
|
||||
function startup() {
|
||||
const { clusters, buckets } = organizeClusters();
|
||||
|
||||
// SPREAD THIS OUT TO DIFFERENT CLUSTERS TO BEGIN STARTING UP
|
||||
// FOREACH will have this concurrently
|
||||
buckets.forEach(async (bucket, bucketID) => {
|
||||
for (const queue of bucket) {
|
||||
for (const shardID of queue) {
|
||||
console.log(
|
||||
`Bucket ID:`,
|
||||
bucketID,
|
||||
"Cluster ID:",
|
||||
clusters.get(shardID),
|
||||
"Shard ID:",
|
||||
shardID,
|
||||
);
|
||||
redis.publish(
|
||||
"sharder",
|
||||
JSON.stringify({ clusterID: clusters.get(shardID), shardID }),
|
||||
);
|
||||
}
|
||||
|
||||
// AFTER THIS QUEUE IS CREATED WE WAIT FOR ALL SHARDS TO LOAD BEFORE NEXT CLUSTER
|
||||
// 5 SECONDS PER SHARD + EXTRA 10 TO BE SAFE
|
||||
await sleep(config.shardsPerCluster * 5000 + 10000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startup();
|
||||
setInterval(startup, 60000 * 5);
|
||||
@@ -2,4 +2,5 @@ export {
|
||||
assertArrayIncludes,
|
||||
assertEquals,
|
||||
assertExists,
|
||||
assertThrows,
|
||||
} from "https://deno.land/std@0.90.0/testing/asserts.ts";
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { ApplicationCommandOption } from "../../src/types/interactions/application_command_option.ts";
|
||||
import { DiscordApplicationCommandOptionTypes } from "../../src/types/interactions/application_command_option_types.ts";
|
||||
import {
|
||||
camelKeysToSnakeCase,
|
||||
snakeKeysToCamelCase,
|
||||
validateSlashCommands,
|
||||
} from "../../src/util/utils.ts";
|
||||
import { assertEquals } from "../deps.ts";
|
||||
import { assertEquals, assertThrows } from "../deps.ts";
|
||||
|
||||
const testSnakeObject = {
|
||||
// deno-lint-ignore camelcase
|
||||
@@ -74,3 +77,52 @@ Deno.test({
|
||||
assertEquals(resultTwo, someElseOther);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[utils] validateSlashCommands(): validates name",
|
||||
fn() {
|
||||
assertThrows(() =>
|
||||
validateSlashCommands([{
|
||||
// The maximum length of the name of an application command is 32.
|
||||
name: "a".repeat(33),
|
||||
}])
|
||||
);
|
||||
|
||||
validateSlashCommands([{
|
||||
name: "workingname",
|
||||
}]);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[utils] validateSlashCommands(): validates description",
|
||||
fn() {
|
||||
assertThrows(() =>
|
||||
// The maximum length of the description of an application command is 100.
|
||||
validateSlashCommands([{ description: "a".repeat(101) }])
|
||||
);
|
||||
|
||||
validateSlashCommands([{
|
||||
description: "valid description (should not throw)",
|
||||
}]);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[utils] validateSlashCommands(): validates number of options",
|
||||
fn() {
|
||||
const option = {
|
||||
name: "option1",
|
||||
description: "The description of the application command's option.",
|
||||
type: DiscordApplicationCommandOptionTypes.STRING,
|
||||
};
|
||||
// The maximum number of options an application command can "accomodate" is 25.
|
||||
const options: ApplicationCommandOption[] = Array(26).fill(option);
|
||||
|
||||
assertThrows(() => validateSlashCommands([{ options }]));
|
||||
|
||||
validateSlashCommands([{
|
||||
options: [option],
|
||||
}]);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user