@hot-updater/test-utils 1.2.0-rc.43 → 1.2.0-rc.44
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.d.mts +8 -0
- package/dist/index.mjs +39 -1
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -291,6 +291,14 @@ interface ReadBudgetSuiteOptions {
|
|
|
291
291
|
readonly cleanup?: () => Promise<void>;
|
|
292
292
|
/** SQL backends: the rows the database examined for the adapter's reads. */
|
|
293
293
|
readonly examined?: RowsExamined;
|
|
294
|
+
/**
|
|
295
|
+
* The rows each statement of the adapter's writes and prunes read, as D1
|
|
296
|
+
* bills them, since `reset`.
|
|
297
|
+
*/
|
|
298
|
+
readonly written?: {
|
|
299
|
+
reset(): void;
|
|
300
|
+
rows(): Promise<readonly number[]>;
|
|
301
|
+
};
|
|
294
302
|
/**
|
|
295
303
|
* Index reads return row copies without `_v`, as the key-value adapter's
|
|
296
304
|
* do, so a transaction reads the rows it guards again, whole.
|
package/dist/index.mjs
CHANGED
|
@@ -4547,6 +4547,7 @@ const READ_BUDGETS = [
|
|
|
4547
4547
|
const setupReadBudgetTestSuite = (options) => {
|
|
4548
4548
|
describe(`${options.name} read budgets`, () => {
|
|
4549
4549
|
let created;
|
|
4550
|
+
let tables;
|
|
4550
4551
|
let database;
|
|
4551
4552
|
let seeded;
|
|
4552
4553
|
let writes = 0;
|
|
@@ -4557,8 +4558,9 @@ const setupReadBudgetTestSuite = (options) => {
|
|
|
4557
4558
|
apiKeys(),
|
|
4558
4559
|
remoteConfig()
|
|
4559
4560
|
];
|
|
4561
|
+
tables = [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE];
|
|
4560
4562
|
created = await options.createAdapter({
|
|
4561
|
-
tables
|
|
4563
|
+
tables,
|
|
4562
4564
|
nativePageSize: NATIVE_PAGE_SIZE
|
|
4563
4565
|
});
|
|
4564
4566
|
const { adapter } = created;
|
|
@@ -4598,6 +4600,42 @@ const setupReadBudgetTestSuite = (options) => {
|
|
|
4598
4600
|
expect(await examined.total(), "rows examined").toBeLessThanOrEqual((examined.perRow ?? 1) * (keys + rows) + (examined.perRead ?? 0) * (gets + queries));
|
|
4599
4601
|
}
|
|
4600
4602
|
});
|
|
4603
|
+
/** Install `n`'s first event, all in one hour of day 4: the same rows each. */
|
|
4604
|
+
const newInstall = (n) => eventOf(400 + n, {
|
|
4605
|
+
install_id: `new-install-${n}`,
|
|
4606
|
+
user_id: null,
|
|
4607
|
+
received_at_ms: T0 + 4 * DAY + n * 1e3
|
|
4608
|
+
});
|
|
4609
|
+
/** Events of later days, which no prune below reaches. */
|
|
4610
|
+
const store = async (from, count) => {
|
|
4611
|
+
for (let n = from; n < from + count; n += 1) await seeded.insights.recordEvent(newInstall(n));
|
|
4612
|
+
};
|
|
4613
|
+
it("record an insights event: no statement reads more than its row and the write's guard row, with 60 or 120 events stored", async (context) => {
|
|
4614
|
+
const { written } = created;
|
|
4615
|
+
if (written === void 0) return context.skip();
|
|
4616
|
+
const most = async (n) => {
|
|
4617
|
+
written.reset();
|
|
4618
|
+
await seeded.insights.recordEvent(newInstall(n));
|
|
4619
|
+
return Math.max(...await written.rows());
|
|
4620
|
+
};
|
|
4621
|
+
await store(1, 60);
|
|
4622
|
+
expect(await most(61)).toBeLessThanOrEqual(2);
|
|
4623
|
+
await store(62, 60);
|
|
4624
|
+
expect(await most(122)).toBeLessThanOrEqual(2);
|
|
4625
|
+
});
|
|
4626
|
+
it("prune: deletes 5 expired events reading no more rows with 60 more events stored", async (context) => {
|
|
4627
|
+
const { adapter, written } = created;
|
|
4628
|
+
if (written === void 0) return context.skip();
|
|
4629
|
+
const events = tables.find(({ name }) => name === "bundle_events");
|
|
4630
|
+
const prune = async () => {
|
|
4631
|
+
written.reset();
|
|
4632
|
+
expect(await adapter.prune(events, T0 - DAY, 5)).toBe(5);
|
|
4633
|
+
return (await written.rows()).reduce((sum, rows) => sum + rows, 0);
|
|
4634
|
+
};
|
|
4635
|
+
const before = await prune();
|
|
4636
|
+
await store(200, 60);
|
|
4637
|
+
expect(await prune()).toBeLessThanOrEqual(before);
|
|
4638
|
+
});
|
|
4601
4639
|
});
|
|
4602
4640
|
};
|
|
4603
4641
|
//#endregion
|
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.44",
|
|
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.44",
|
|
54
|
+
"@hot-updater/protocol": "^1.2.0-rc.44",
|
|
55
|
+
"@hot-updater/server": "^1.2.0-rc.44",
|
|
56
|
+
"@hot-updater/plugin-core": "^1.2.0-rc.44"
|
|
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/plugin-insights": "1.2.0-rc.
|
|
88
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
89
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
90
|
-
"@hot-updater/server": "1.2.0-rc.
|
|
87
|
+
"@hot-updater/plugin-insights": "1.2.0-rc.44",
|
|
88
|
+
"@hot-updater/protocol": "1.2.0-rc.44",
|
|
89
|
+
"@hot-updater/plugin-core": "1.2.0-rc.44",
|
|
90
|
+
"@hot-updater/server": "1.2.0-rc.44"
|
|
91
91
|
},
|
|
92
92
|
"inlinedDependencies": {
|
|
93
93
|
"@clack/core": "1.4.3",
|