Public: anyone can read this; the crew can change it.

A test file that sets the pinned `net` gives it back, and pinned-ceiling starts clean (#302) #17776

opened this

Merged 15h 20m ago, live in production

cf/pinned-net → main 0 commits

  • Merged. cf/pinned-net was merged into main as 1540995.

Review

Sign in to review this change.
6 files changed +69 −0
test/helpers/own-net.ts added +27
@@ -0,0 +1,27 @@
1 /**
2 * The pinned actions' `net` and the cloud accounts' `net` for one test file, and given back. Each
3 * is one object for the process, and the suite runs many files in one: `order-cloud` and
4 * `new-forge-clouds` left a `resolve` that reads their own database, closed by then. Beside
5 * `globals.ts`, not in it: many tests import that one and need none of the pinned actions.
6 *
7 * Called at a file's top level, it holds for that file: no name resolves, every probe is answered
8 * 200 and there is no boot limit, until the file sets its own.
9 */
10
11 import { afterAll, beforeAll } from "bun:test";
12 import { net as cloudNet } from "../../src/actions/cloud.ts";
13 import { net } from "../../src/actions/pinned.ts";
14
15 export function ownNet(): void {
16 let found: { pinned: typeof net; cloud: typeof cloudNet };
17 beforeAll(() => {
18 found = { pinned: { ...net }, cloud: { ...cloudNet } };
19 net.resolve = async () => [];
20 net.probe = async () => new Response("ok", { status: 200 });
21 net.bootLimit = undefined;
22 });
23 afterAll(() => {
24 Object.assign(net, { bootLimit: undefined }, found.pinned);
25 Object.assign(cloudNet, found.cloud);
26 });
27 }
test/new-forge-clouds.test.ts +2
@@ -32,9 +32,11 @@ import { cloudsOffered, NO_CHARGE, parseWhere, whereChoices, whereFields, whereH
3232 import { newForgePage, newForgeSubmit } from "../src/web/pages/new-forge.ts";
3333 import { pricingDone } from "../src/web/pages/pricing.ts";
3434 import { quietLogs } from "./helpers/globals.ts";
35 import { ownNet } from "./helpers/own-net.ts";
3536 import { seedPlaces } from "./helpers/places-fixture.ts";
3637
3738 quietLogs();
39 ownNet();
3840 makingWatch.tries = 0;
3941
4042 const COMMIT = "d".repeat(40);
test/order-cloud.test.ts +2
@@ -52,9 +52,11 @@ import { usePlacement } from "../src/spawn/door.ts";
5252 import { bootHostedChild, closeHostedChildren } from "../src/spawn/host.ts";
5353 import { getPaidPlacement } from "../src/settings/paid_placement.ts";
5454 import { quietLogs } from "./helpers/globals.ts";
55 import { ownNet } from "./helpers/own-net.ts";
5556 import { ocean, seedPlaces } from "./helpers/places-fixture.ts";
5657
5758 quietLogs();
59 ownNet();
5860
5961 const COMMIT = "c".repeat(40);
6062 // No page and no test waits on the in-process watch: each asks the order itself.
test/own-net.test.ts added +34
@@ -0,0 +1,34 @@
1 /**
2 * `ownNet` (`helpers/own-net.ts`): what a file sets on the shared `net` objects ends with it, and
3 * what the last file left is not its own.
4 */
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6 import { net as cloudNet } from "../src/actions/cloud.ts";
7 import { net } from "../src/actions/pinned.ts";
8 import { ownNet } from "./helpers/own-net.ts";
9
10 const before = { pinned: { ...net }, cloud: { ...cloudNet } };
11 /** What a file that gave nothing back leaves: a resolve over a closed database, and a limit. */
12 const left = { resolve: () => Promise.reject(new Error("Cannot use a closed database")), bootLimit: 10 };
13 beforeAll(() => void Object.assign(net, left));
14 afterAll(() => {
15 Object.assign(net, { bootLimit: undefined }, before.pinned);
16 Object.assign(cloudNet, before.cloud);
17 });
18
19 describe("a file that asks for its own", () => {
20 ownNet();
21
22 test("starts on answers of its own, not on what the last file left", async () => {
23 expect(await net.resolve("acme.forge.test")).toEqual([]);
24 expect((await net.probe("https://acme.forge.test/")).status).toBe(200);
25 expect(net.bootLimit).toBeUndefined();
26 net.resolve = async () => ["203.0.113.7"];
27 net.fetch = cloudNet.fetch = async () => new Response("its own");
28 });
29 });
30
31 test("and once it ends, everything it set is as it found it", () => {
32 expect(net).toMatchObject({ ...left, fetch: before.pinned.fetch, probe: before.pinned.probe });
33 expect(cloudNet.fetch).toBe(before.cloud.fetch);
34 });
test/pinned-ceiling.test.ts +2
@@ -19,10 +19,12 @@ import { getCloudAccount } from "../src/core/cloud_account.ts";
1919 import { getPinned } from "../src/core/pinned.ts";
2020 import { createUser, getUserByName } from "../src/core/users.ts";
2121 import { quietLogs } from "./helpers/globals.ts";
22 import { ownNet } from "./helpers/own-net.ts";
2223 import { recordCloud } from "./helpers/recorded-cloud.ts";
2324 import { seedPlaces } from "./helpers/places-fixture.ts";
2425
2526 quietLogs();
27 ownNet();
2628
2729 const V1 = "a".repeat(40);
2830 const V2 = "b".repeat(40);
test/pinned-forge.test.ts +2
@@ -18,10 +18,12 @@ import { createToken } from "../src/core/tokens.ts";
1818 import { createUser, getUserByName } from "../src/core/users.ts";
1919 import { serve, type Servers } from "../src/http/server.ts";
2020 import { quietLogs } from "./helpers/globals.ts";
21 import { ownNet } from "./helpers/own-net.ts";
2122 import { recordCloud, sequence } from "./helpers/recorded-cloud.ts";
2223 import { seedPlaces } from "./helpers/places-fixture.ts";
2324
2425 quietLogs();
26 ownNet();
2527
2628 const TOKEN = "dop_v1_9Zq4TxLm7Kp2Vb8nWcR5";
2729 const V1 = "a".repeat(40);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs