@hot-updater/test-utils 1.1.13 → 1.1.15

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 CHANGED
@@ -289,6 +289,14 @@ interface ReadBudgetSuiteOptions {
289
289
  readonly cleanup?: () => Promise<void>;
290
290
  /** SQL backends: the rows the database examined for the adapter's reads. */
291
291
  readonly examined?: RowsExamined;
292
+ /**
293
+ * The rows each statement of the adapter's writes and prunes read, as D1
294
+ * bills them, since `reset`.
295
+ */
296
+ readonly written?: {
297
+ reset(): void;
298
+ rows(): Promise<readonly number[]>;
299
+ };
292
300
  /**
293
301
  * Index reads return row copies without `_v`, as the key-value adapter's
294
302
  * do, so a transaction reads the rows it guards again, whole.
package/dist/index.mjs CHANGED
@@ -3516,6 +3516,7 @@ const READ_BUDGETS = [
3516
3516
  const setupReadBudgetTestSuite = (options) => {
3517
3517
  describe(`${options.name} read budgets`, () => {
3518
3518
  let created;
3519
+ let tables;
3519
3520
  let database;
3520
3521
  let seeded;
3521
3522
  let writes = 0;
@@ -3526,8 +3527,9 @@ const setupReadBudgetTestSuite = (options) => {
3526
3527
  apiKeys(),
3527
3528
  remoteConfig()
3528
3529
  ];
3530
+ tables = [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE];
3529
3531
  created = await options.createAdapter({
3530
- tables: [...toolingTargetOf(plugins).schema.tables, SETTINGS_TABLE],
3532
+ tables,
3531
3533
  nativePageSize: NATIVE_PAGE_SIZE
3532
3534
  });
3533
3535
  const { adapter } = created;
@@ -3567,6 +3569,42 @@ const setupReadBudgetTestSuite = (options) => {
3567
3569
  expect(await examined.total(), "rows examined").toBeLessThanOrEqual((examined.perRow ?? 1) * (keys + rows) + (examined.perRead ?? 0) * (gets + queries));
3568
3570
  }
3569
3571
  });
3572
+ /** Install `n`'s first event, all in one hour of day 4: the same rows each. */
3573
+ const newInstall = (n) => eventOf(400 + n, {
3574
+ install_id: `new-install-${n}`,
3575
+ user_id: null,
3576
+ received_at_ms: T0 + 4 * DAY + n * 1e3
3577
+ });
3578
+ /** Events of later days, which no prune below reaches. */
3579
+ const store = async (from, count) => {
3580
+ for (let n = from; n < from + count; n += 1) await seeded.insights.recordEvent(newInstall(n));
3581
+ };
3582
+ 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) => {
3583
+ const { written } = created;
3584
+ if (written === void 0) return context.skip();
3585
+ const most = async (n) => {
3586
+ written.reset();
3587
+ await seeded.insights.recordEvent(newInstall(n));
3588
+ return Math.max(...await written.rows());
3589
+ };
3590
+ await store(1, 60);
3591
+ expect(await most(61)).toBeLessThanOrEqual(2);
3592
+ await store(62, 60);
3593
+ expect(await most(122)).toBeLessThanOrEqual(2);
3594
+ });
3595
+ it("prune: deletes 5 expired events reading no more rows with 60 more events stored", async (context) => {
3596
+ const { adapter, written } = created;
3597
+ if (written === void 0) return context.skip();
3598
+ const events = tables.find(({ name }) => name === "bundle_events");
3599
+ const prune = async () => {
3600
+ written.reset();
3601
+ expect(await adapter.prune(events, T0 - DAY, 5)).toBe(5);
3602
+ return (await written.rows()).reduce((sum, rows) => sum + rows, 0);
3603
+ };
3604
+ const before = await prune();
3605
+ await store(200, 60);
3606
+ expect(await prune()).toBeLessThanOrEqual(before);
3607
+ });
3570
3608
  });
3571
3609
  };
3572
3610
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/test-utils",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
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.1.13",
54
- "@hot-updater/protocol": "^1.1.13",
55
- "@hot-updater/server": "^1.1.13",
56
- "@hot-updater/plugin-core": "^1.1.13"
53
+ "@hot-updater/plugin-insights": "^1.1.15",
54
+ "@hot-updater/protocol": "^1.1.15",
55
+ "@hot-updater/plugin-core": "^1.1.15",
56
+ "@hot-updater/server": "^1.1.15"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@electric-sql/pglite": {
@@ -83,10 +83,10 @@
83
83
  "typescript": "npm:@typescript/typescript6@6.0.2",
84
84
  "vitest": "4.1.4",
85
85
  "workspace-tools": "^0.42.3",
86
- "@hot-updater/plugin-insights": "1.1.13",
87
- "@hot-updater/plugin-core": "1.1.13",
88
- "@hot-updater/server": "1.1.13",
89
- "@hot-updater/protocol": "1.1.13"
86
+ "@hot-updater/plugin-insights": "1.1.15",
87
+ "@hot-updater/protocol": "1.1.15",
88
+ "@hot-updater/server": "1.1.15",
89
+ "@hot-updater/plugin-core": "1.1.15"
90
90
  },
91
91
  "inlinedDependencies": {
92
92
  "@nodelib/fs.scandir": "2.1.5",