@hot-updater/test-utils 1.2.0-rc.49 → 1.2.0-rc.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +260 -1
- package/package.json +9 -9
package/dist/index.mjs
CHANGED
|
@@ -290,6 +290,72 @@ const setupCoreAdminTestSuite = (options) => {
|
|
|
290
290
|
expect(missing.status).toBe(404);
|
|
291
291
|
await missing.text();
|
|
292
292
|
});
|
|
293
|
+
it("reads channels by ID and pages them by name", async () => {
|
|
294
|
+
const [a, b, c] = await Promise.all([
|
|
295
|
+
"a",
|
|
296
|
+
"b",
|
|
297
|
+
"c"
|
|
298
|
+
].map((suffix) => api.ensureChannel(`page-${namespace}-${suffix}`)));
|
|
299
|
+
expect((await adminJson(`/channels?ids=${c.id},${a.id},${namespace}`)).data).toEqual([c, a]);
|
|
300
|
+
const first = await adminJson(`/channels?limit=2&cursor=${encodeURIComponent(`page-${namespace}-`)}`);
|
|
301
|
+
expect(first).toEqual({
|
|
302
|
+
data: [a, b],
|
|
303
|
+
next: b.name
|
|
304
|
+
});
|
|
305
|
+
const second = await adminJson(`/channels?limit=2&cursor=${encodeURIComponent(first.next)}`);
|
|
306
|
+
expect(second.data[0]).toEqual(c);
|
|
307
|
+
for (const channel of [
|
|
308
|
+
a,
|
|
309
|
+
b,
|
|
310
|
+
c
|
|
311
|
+
]) {
|
|
312
|
+
const deleted = await admin(`/channels/${channel.id}`, jsonRequest("DELETE"));
|
|
313
|
+
expect(deleted.status).toBe(204);
|
|
314
|
+
await deleted.text();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
it("lists every scope that has releases by keyset pages", async () => {
|
|
318
|
+
const deployed = [
|
|
319
|
+
await api.deploy({
|
|
320
|
+
bundle: toDeployBundle(bundleRow("21")),
|
|
321
|
+
release: policy("scopes-a")
|
|
322
|
+
}),
|
|
323
|
+
await api.deploy({
|
|
324
|
+
bundle: toDeployBundle(bundleRow("22")),
|
|
325
|
+
release: policy("scopes-a")
|
|
326
|
+
}),
|
|
327
|
+
await api.deploy({
|
|
328
|
+
bundle: toDeployBundle(bundleRow("23")),
|
|
329
|
+
release: policy("scopes-b")
|
|
330
|
+
})
|
|
331
|
+
];
|
|
332
|
+
const scopeKeys = [];
|
|
333
|
+
for (let cursor;;) {
|
|
334
|
+
const page = await adminJson(`/release-scopes?limit=2${cursor === void 0 ? "" : `&cursor=${encodeURIComponent(cursor)}`}`);
|
|
335
|
+
scopeKeys.push(...page.data);
|
|
336
|
+
if (page.next === void 0) break;
|
|
337
|
+
expect(page.next).toBe(page.data.at(-1));
|
|
338
|
+
cursor = page.next;
|
|
339
|
+
}
|
|
340
|
+
expect(scopeKeys).toEqual([...new Set(scopeKeys)].sort());
|
|
341
|
+
expect(scopeKeys).toEqual(expect.arrayContaining([...new Set(deployed.map(({ scope_key }) => scope_key))]));
|
|
342
|
+
const refusals = await Promise.all(["/release-scopes?limit=101", "/release-scopes?order=desc"].map(async (path) => (await admin(path)).status));
|
|
343
|
+
expect(refusals).toEqual([400, 400]);
|
|
344
|
+
});
|
|
345
|
+
it("takes at most 100 IDs a request", async () => {
|
|
346
|
+
const ids = Array.from({ length: 101 }, () => crypto.randomUUID());
|
|
347
|
+
const refusals = [[await admin(`/channels?ids=${ids.join(",")}`), "Channels by ID take ids=<channel id>,... with 1 to 100 ids."], [await admin("/ios-devices/in-build", jsonRequest("POST", {
|
|
348
|
+
buildId: crypto.randomUUID(),
|
|
349
|
+
ids
|
|
350
|
+
})), "Marking iOS devices in a build takes at most 100 ids a request."]];
|
|
351
|
+
expect(await Promise.all(refusals.map(async ([response]) => ({
|
|
352
|
+
status: response.status,
|
|
353
|
+
body: await response.json().catch(() => null)
|
|
354
|
+
})))).toEqual(refusals.map(([, error]) => ({
|
|
355
|
+
status: 400,
|
|
356
|
+
body: expect.objectContaining({ error })
|
|
357
|
+
})));
|
|
358
|
+
});
|
|
293
359
|
it("keeps a release's channel when a delete races the deploy into it", async () => {
|
|
294
360
|
const channel = await api.ensureChannel(`race-${namespace}`);
|
|
295
361
|
const [deleted, release] = await Promise.all([admin(`/channels/${channel.id}`, jsonRequest("DELETE")), api.deploy({
|
|
@@ -1569,7 +1635,7 @@ const setupReleaseCatalogTestSuite = (options) => {
|
|
|
1569
1635
|
expect((await request(otherPath)).status).toBe(404);
|
|
1570
1636
|
});
|
|
1571
1637
|
it("caches an unknown scope's 404 like a catalog", async () => {
|
|
1572
|
-
const response = await request(catalogPath());
|
|
1638
|
+
const response = await request(catalogPath(scope("unknown")));
|
|
1573
1639
|
expect(response.status).toBe(404);
|
|
1574
1640
|
expect(response.headers.get("cache-control")).toBe("public, max-age=0, s-maxage=5");
|
|
1575
1641
|
expect(response.headers.get("cdn-cache-control")).toBe("public, max-age=5, stale-while-revalidate=5, stale-if-error=0");
|
|
@@ -2666,6 +2732,60 @@ const setupDatabaseAdapterConformanceSuite = (options) => {
|
|
|
2666
2732
|
"r8"
|
|
2667
2733
|
]);
|
|
2668
2734
|
});
|
|
2735
|
+
it("reads every write committed before the read starts", async () => {
|
|
2736
|
+
const adapter = await setup();
|
|
2737
|
+
await ok(adapter, [insert(item("s", { score: 1 }))]);
|
|
2738
|
+
for (let score = 2; score <= 5; score += 1) {
|
|
2739
|
+
const previous = await one(adapter, "s");
|
|
2740
|
+
await ok(adapter, [{
|
|
2741
|
+
type: "patch",
|
|
2742
|
+
table: conformanceItems,
|
|
2743
|
+
key: ["s"],
|
|
2744
|
+
set: { score },
|
|
2745
|
+
guard: { v: previous._v },
|
|
2746
|
+
previous
|
|
2747
|
+
}]);
|
|
2748
|
+
expect((await one(adapter, "s"))?.score).toBe(score);
|
|
2749
|
+
expect((await query(adapter, {
|
|
2750
|
+
index: "byGroup",
|
|
2751
|
+
eq: ["g"]
|
|
2752
|
+
})).map((row) => row.score)).toEqual([score]);
|
|
2753
|
+
}
|
|
2754
|
+
});
|
|
2755
|
+
it("writes the index items of rows written without the index (migrations.fillIndex)", async () => {
|
|
2756
|
+
const adapter = await setup();
|
|
2757
|
+
const fillIndex = adapter.migrations?.fillIndex;
|
|
2758
|
+
if (fillIndex === void 0) return;
|
|
2759
|
+
const earlier = {
|
|
2760
|
+
...conformanceItems,
|
|
2761
|
+
indexes: conformanceItems.indexes.filter(({ name }) => name !== "byGroup")
|
|
2762
|
+
};
|
|
2763
|
+
await ok(adapter, [
|
|
2764
|
+
"r0",
|
|
2765
|
+
"r1",
|
|
2766
|
+
"r2"
|
|
2767
|
+
].map((id) => ({
|
|
2768
|
+
type: "insert",
|
|
2769
|
+
table: earlier,
|
|
2770
|
+
row: item(id, { score: Number(id.slice(1)) })
|
|
2771
|
+
})));
|
|
2772
|
+
await ok(adapter, [insert(item("r3", { score: 3 }))]);
|
|
2773
|
+
const byGroup = () => query(adapter, {
|
|
2774
|
+
index: "byGroup",
|
|
2775
|
+
eq: ["g"]
|
|
2776
|
+
}).then(ids);
|
|
2777
|
+
await expect(byGroup()).resolves.toEqual(["r3"]);
|
|
2778
|
+
await expect(fillIndex(conformanceItems, "byGroup", { dryRun: true })).resolves.toBe(3);
|
|
2779
|
+
await expect(byGroup()).resolves.toEqual(["r3"]);
|
|
2780
|
+
await expect(fillIndex(conformanceItems, "byGroup")).resolves.toBe(3);
|
|
2781
|
+
await expect(byGroup()).resolves.toEqual([
|
|
2782
|
+
"r0",
|
|
2783
|
+
"r1",
|
|
2784
|
+
"r2",
|
|
2785
|
+
"r3"
|
|
2786
|
+
]);
|
|
2787
|
+
await expect(fillIndex(conformanceItems, "byGroup", { dryRun: true })).resolves.toBe(0);
|
|
2788
|
+
});
|
|
2669
2789
|
it(`lets exactly one of ${writers} concurrent writers win a contested key`, async () => {
|
|
2670
2790
|
const adapter = await setup();
|
|
2671
2791
|
const row = item("a");
|
|
@@ -3461,6 +3581,49 @@ const failureOf = (n, install, check = false) => eventOf(200 + n, {
|
|
|
3461
3581
|
},
|
|
3462
3582
|
received_at_ms: T0 + 3 * DAY + n * 10 * 6e4
|
|
3463
3583
|
});
|
|
3584
|
+
/** Where a client floods update failures: Android `flood`, day 5. */
|
|
3585
|
+
const FLOOD = {
|
|
3586
|
+
platform: "android",
|
|
3587
|
+
channel: "flood",
|
|
3588
|
+
start: T0 + 5 * DAY
|
|
3589
|
+
};
|
|
3590
|
+
/** The flood's failed checks: more breakdown rows than a read takes from an hour. */
|
|
3591
|
+
const FLOOD_CHECKS = 24;
|
|
3592
|
+
/**
|
|
3593
|
+
* Installations whose IDs fall on all 8 counter shards: each flood row is
|
|
3594
|
+
* reported by all of them, so it is stored on every shard.
|
|
3595
|
+
*/
|
|
3596
|
+
const FLOOD_INSTALLS = Array.from({ length: 8 }, (_, n) => `flood-${n}`);
|
|
3597
|
+
/**
|
|
3598
|
+
* Flood failure `n`: below {@link FLOOD_CHECKS} × 8, a failed check of HTTP
|
|
3599
|
+
* status 100 + n / 8 by installation n % 8, all in day 5's first hour; at
|
|
3600
|
+
* it, a real failure, a failed download in the hour after.
|
|
3601
|
+
*/
|
|
3602
|
+
const floodFailureOf = (n) => {
|
|
3603
|
+
const real = n === FLOOD_CHECKS * FLOOD_INSTALLS.length;
|
|
3604
|
+
return eventOf(1e3 + n, {
|
|
3605
|
+
type: "UPDATE_FAILED",
|
|
3606
|
+
install_id: real ? "flood-real" : FLOOD_INSTALLS[n % 8],
|
|
3607
|
+
user_id: null,
|
|
3608
|
+
to_release_id: real ? "release-b" : null,
|
|
3609
|
+
to_bundle_id: real ? "bundle-b" : "bundle-a",
|
|
3610
|
+
platform: FLOOD.platform,
|
|
3611
|
+
channel: FLOOD.channel,
|
|
3612
|
+
metadata: {
|
|
3613
|
+
...eventOf(0).metadata,
|
|
3614
|
+
failure: real ? {
|
|
3615
|
+
stage: "download",
|
|
3616
|
+
reason: "http",
|
|
3617
|
+
http_status: 403
|
|
3618
|
+
} : {
|
|
3619
|
+
stage: "check",
|
|
3620
|
+
reason: "http",
|
|
3621
|
+
http_status: 100 + Math.floor(n / 8)
|
|
3622
|
+
}
|
|
3623
|
+
},
|
|
3624
|
+
received_at_ms: FLOOD.start + (real ? HOUR : n * 1e3)
|
|
3625
|
+
});
|
|
3626
|
+
};
|
|
3464
3627
|
/**
|
|
3465
3628
|
* History event `n` of the day before T0, three an hour, on its own release
|
|
3466
3629
|
* and bundles: every windowed read, which starts at T0 or later, skips it.
|
|
@@ -3660,6 +3823,7 @@ const seed = async (database) => {
|
|
|
3660
3823
|
await api.insights.recordEvent(failureOf(1, 3));
|
|
3661
3824
|
await api.insights.recordEvent(failureOf(2, 5));
|
|
3662
3825
|
await api.insights.recordEvent(failureOf(3, 7, true));
|
|
3826
|
+
for (let n = 0; n <= FLOOD_CHECKS * FLOOD_INSTALLS.length; n += 1) await api.insights.recordEvent(floodFailureOf(n));
|
|
3663
3827
|
for (const [baseVersion, greeting] of [
|
|
3664
3828
|
"Hi",
|
|
3665
3829
|
"Hello",
|
|
@@ -3872,6 +4036,46 @@ const READ_BUDGETS = [
|
|
|
3872
4036
|
rows: 1
|
|
3873
4037
|
}
|
|
3874
4038
|
}),
|
|
4039
|
+
budget({
|
|
4040
|
+
api: "catalog preflight: 1 catalog point read and the scope's enabled releases",
|
|
4041
|
+
read: ({ core }) => core.preflightReleaseCatalogRebuild(scopeKey),
|
|
4042
|
+
adapter: reads(1, 1, 1, 4),
|
|
4043
|
+
engine: {
|
|
4044
|
+
calls: 2,
|
|
4045
|
+
rows: 5
|
|
4046
|
+
},
|
|
4047
|
+
check: (preflight) => expect(preflight.changed).toBe(false)
|
|
4048
|
+
}),
|
|
4049
|
+
budget({
|
|
4050
|
+
api: "release scopes: one limit-1 seek per scope, past each scope's releases",
|
|
4051
|
+
read: ({ core }) => core.listReleaseScopeKeys({ limit: 4 }),
|
|
4052
|
+
adapter: reads(0, 0, 4, 4),
|
|
4053
|
+
engine: {
|
|
4054
|
+
calls: 4,
|
|
4055
|
+
rows: 4
|
|
4056
|
+
},
|
|
4057
|
+
returned: (scopeKeys) => scopeKeys.length,
|
|
4058
|
+
check: (scopeKeys) => expect(scopeKeys).toEqual([
|
|
4059
|
+
"v1:app-version:android:cHJvZHVjdGlvbg",
|
|
4060
|
+
"v1:app-version:ios:YmV0YQ",
|
|
4061
|
+
"v1:app-version:ios:c3RhZ2luZw",
|
|
4062
|
+
scopeKey
|
|
4063
|
+
])
|
|
4064
|
+
}),
|
|
4065
|
+
budget({
|
|
4066
|
+
api: "release scopes past the last: 1 empty query",
|
|
4067
|
+
read: ({ core }) => core.listReleaseScopeKeys({
|
|
4068
|
+
after: scopeKey,
|
|
4069
|
+
limit: 4
|
|
4070
|
+
}),
|
|
4071
|
+
adapter: reads(0, 0, 1, 0),
|
|
4072
|
+
engine: {
|
|
4073
|
+
calls: 1,
|
|
4074
|
+
rows: 0
|
|
4075
|
+
},
|
|
4076
|
+
returned: (scopeKeys) => scopeKeys.length,
|
|
4077
|
+
check: (scopeKeys) => expect(scopeKeys).toEqual([])
|
|
4078
|
+
}),
|
|
3875
4079
|
budget({
|
|
3876
4080
|
api: "native build by ID: 1 point read",
|
|
3877
4081
|
read: ({ core }) => core.getNativeBuild(createBundleFixture("8012").id),
|
|
@@ -4072,6 +4276,35 @@ const READ_BUDGETS = [
|
|
|
4072
4276
|
},
|
|
4073
4277
|
returned: (channel) => channel === null ? 0 : 1
|
|
4074
4278
|
}),
|
|
4279
|
+
budget({
|
|
4280
|
+
api: "channels by ID: 1 batch get of their keys",
|
|
4281
|
+
read: ({ core, productionId, nightlyId }) => core.getChannels([
|
|
4282
|
+
nightlyId,
|
|
4283
|
+
productionId,
|
|
4284
|
+
nightlyId
|
|
4285
|
+
]),
|
|
4286
|
+
adapter: reads(1, 2, 0, 0),
|
|
4287
|
+
engine: {
|
|
4288
|
+
calls: 1,
|
|
4289
|
+
rows: 2
|
|
4290
|
+
},
|
|
4291
|
+
returned: (channels) => channels.length,
|
|
4292
|
+
check: (channels) => expect(channels.map(({ name }) => name)).toEqual(["nightly", "production"])
|
|
4293
|
+
}),
|
|
4294
|
+
budget({
|
|
4295
|
+
api: "channel page by name: limit rows from one query",
|
|
4296
|
+
read: ({ core }) => core.listChannels({
|
|
4297
|
+
limit: 2,
|
|
4298
|
+
after: "beta"
|
|
4299
|
+
}),
|
|
4300
|
+
adapter: reads(0, 0, 1, 2),
|
|
4301
|
+
engine: {
|
|
4302
|
+
calls: 1,
|
|
4303
|
+
rows: 2
|
|
4304
|
+
},
|
|
4305
|
+
returned: (channels) => channels.length,
|
|
4306
|
+
check: (channels) => expect(channels.map(({ name }) => name)).toEqual(["canary", "nightly"])
|
|
4307
|
+
}),
|
|
4075
4308
|
budget({
|
|
4076
4309
|
api: "list events of a dense day: limit rows from one query",
|
|
4077
4310
|
read: ({ insights }) => insights.listEvents({
|
|
@@ -4289,6 +4522,32 @@ const READ_BUDGETS = [
|
|
|
4289
4522
|
checks: { failures: 1 }
|
|
4290
4523
|
})
|
|
4291
4524
|
}),
|
|
4525
|
+
budget({
|
|
4526
|
+
api: "update failures of a flooded channel: 20 breakdown rows of the flooded hour, every other hour whole",
|
|
4527
|
+
read: ({ insights }) => insights.getUpdateFailures({
|
|
4528
|
+
platform: FLOOD.platform,
|
|
4529
|
+
channel: FLOOD.channel,
|
|
4530
|
+
timeRange: {
|
|
4531
|
+
start: FLOOD.start,
|
|
4532
|
+
end: FLOOD.start + 2 * HOUR
|
|
4533
|
+
}
|
|
4534
|
+
}),
|
|
4535
|
+
adapter: reads(1, 1, 5, 177),
|
|
4536
|
+
engine: {
|
|
4537
|
+
calls: 5,
|
|
4538
|
+
rows: 24
|
|
4539
|
+
},
|
|
4540
|
+
check: (failures) => expect(failures).toMatchObject({
|
|
4541
|
+
coverage: { kind: "partial" },
|
|
4542
|
+
cappedHours: [FLOOD.start],
|
|
4543
|
+
failedUpdates: 1,
|
|
4544
|
+
failedInstallations: 1,
|
|
4545
|
+
checks: {
|
|
4546
|
+
failures: 160,
|
|
4547
|
+
failedInstallations: 8
|
|
4548
|
+
}
|
|
4549
|
+
})
|
|
4550
|
+
}),
|
|
4292
4551
|
budget({
|
|
4293
4552
|
api: "update failures of a release since its first: two kept rows × shards, all used",
|
|
4294
4553
|
read: ({ insights }) => insights.getUpdateFailures({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/test-utils",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Test utilities for Hot Updater packages",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"mysql2": "*",
|
|
51
51
|
"pg": "*",
|
|
52
52
|
"vitest": "^4.0.0",
|
|
53
|
-
"@hot-updater/plugin-insights": "^1.2.0-rc.
|
|
54
|
-
"@hot-updater/protocol": "^1.2.0-rc.
|
|
55
|
-
"@hot-updater/
|
|
56
|
-
"@hot-updater/
|
|
53
|
+
"@hot-updater/plugin-insights": "^1.2.0-rc.50",
|
|
54
|
+
"@hot-updater/protocol": "^1.2.0-rc.50",
|
|
55
|
+
"@hot-updater/plugin-core": "^1.2.0-rc.50",
|
|
56
|
+
"@hot-updater/server": "^1.2.0-rc.50"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
59
59
|
"@electric-sql/pglite": {
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
85
85
|
"vitest": "4.1.4",
|
|
86
86
|
"workspace-tools": "^0.42.3",
|
|
87
|
-
"@hot-updater/
|
|
88
|
-
"@hot-updater/
|
|
89
|
-
"@hot-updater/
|
|
90
|
-
"@hot-updater/
|
|
87
|
+
"@hot-updater/protocol": "1.2.0-rc.50",
|
|
88
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.50",
|
|
89
|
+
"@hot-updater/plugin-core": "1.2.0-rc.50",
|
|
90
|
+
"@hot-updater/server": "1.2.0-rc.50"
|
|
91
91
|
},
|
|
92
92
|
"inlinedDependencies": {
|
|
93
93
|
"@clack/core": "1.4.3",
|