Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): bound settled-shell cutoff allocation #28931

Closedhieu-lee(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/28931/headopened View on GitHub

Showing 2 changed files with 54 additions and 3 deletions.

x
0 of 2 viewed, 2 left
29 additions and 0 deletionsapps/server/src/orchestration-v2/ShellStream.test.tsModified
View file
@@ -282,6 +282,35 @@
expect(result.threads.map((thread) => thread.id).slice(25)).toEqual(["tie"]);
});
​
+ it("finds the same cut whatever order the settled threads arrive in", () => {
+ const ascending = Array.from({ length: 200 }, (_, index) =>
+ row(`${index % 2 === 0 ? "a" : "b"}-${index}`, index),
+ );
+ let seed = 7;
+ const shuffled = [...ascending];
+ for (let index = shuffled.length - 1; index > 0; index--) {
+ seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
+ const other = seed % (index + 1);
+ [shuffled[index], shuffled[other]] = [shuffled[other]!, shuffled[index]!];
+ }
+ const newestIds = new Set(ascending.slice(0, 25).map((thread) => thread.id));
+ for (const threads of [ascending, [...ascending].reverse(), shuffled]) {
+ const result = omit(threads);
+ expect(result.threads.map((thread) => thread.id)).toEqual(
+ threads.filter((thread) => newestIds.has(thread.id)).map((thread) => thread.id),
+ );
+ expect(result.olderSettled.before).toBe(
+ DateTime.formatIso(DateTime.makeUnsafe(100 * DAY - 24 * DAY)),
+ );
+ expect(result.olderSettled.counts).toEqual(
+ expect.arrayContaining([
+ { projectId: "project-a", count: 87 },
+ { projectId: "project-b", count: 88 },
+ ]),
+ );