@superhero/eventflow-db 4.8.6 → 4.8.7

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/README.md CHANGED
@@ -403,10 +403,10 @@ PARTITION BY RANGE (TO_DAYS(timestamp))
403
403
 
404
404
  ### Build the Environment
405
405
 
406
- The `build` script launches a MySQL container for testing:
406
+ The `test-build` script launches a MySQL container for testing:
407
407
 
408
408
  ```sh
409
- npm run build
409
+ npm run test-build
410
410
  ```
411
411
 
412
412
  ## Running Tests
package/index.test.js CHANGED
@@ -310,6 +310,77 @@ suite('@superhero/eventflow-db', async () =>
310
310
  await assert.doesNotReject(db.persistLog(log))
311
311
  })
312
312
 
313
+ await sub.test('Read same-timestamp records deterministically', async () =>
314
+ {
315
+ const
316
+ suffix = Date.now().toString(36),
317
+ timestamp = '2000-01-01 00:00:00.000',
318
+ scheduled = new Date(Date.now() + 60e3),
319
+ domain = `order_domain_${suffix}`,
320
+ pid = `order_pid_${suffix}`,
321
+ cpid = `order_cpid_${suffix}`,
322
+ eid = `order_eid_${suffix}`,
323
+ hubA = `order_hub_${suffix}_a`,
324
+ hubB = `order_hub_${suffix}_b`,
325
+ eventA = `order_event_${suffix}_a`,
326
+ eventB = `order_event_${suffix}_b`,
327
+ eventBase = { timestamp, domain, pid, name:'order_event', data:{} }
328
+
329
+ await db.persistHub(
330
+ {
331
+ id : hubB,
332
+ timestamp,
333
+ external_ip : '127.0.0.1',
334
+ external_port : 50102,
335
+ internal_ip : '127.0.0.1',
336
+ internal_port : 50102
337
+ })
338
+
339
+ await db.persistHub(
340
+ {
341
+ id : hubA,
342
+ timestamp,
343
+ external_ip : '127.0.0.1',
344
+ external_port : 50101,
345
+ internal_ip : '127.0.0.1',
346
+ internal_port : 50101
347
+ })
348
+
349
+ await db.persistEvent({ ...eventBase, id:eventB, name:'order_event_b' })
350
+ await db.persistEvent({ ...eventBase, id:eventA, name:'order_event_a' })
351
+ await db.persistEventCpid(eventB, domain, cpid)
352
+ await db.persistEventCpid(eventA, domain, cpid)
353
+ await db.persistEventEid(eventB, eid)
354
+ await db.persistEventEid(eventA, eid)
355
+ await db.persistEventScheduled({ event_id:eventB, timestamp, scheduled })
356
+ await db.persistEventScheduled({ event_id:eventA, timestamp, scheduled })
357
+
358
+ const
359
+ orderedIDs = [ eventA, eventB ],
360
+ onlineHubs = await db.readOnlineHubs(),
361
+ eventlog = await db.readEventsByDomainAndPid(domain, pid),
362
+ rangeEvents = await db.readEventsByDomainAndPidBetweenTimestamps(domain, pid, timestamp, timestamp),
363
+ namedEvents = await db.readEventsByDomainAndPidAndNames(domain, pid, [ 'order_event_a', 'order_event_b' ]),
364
+ cpidEvents = await db.readEventsByDomainAndCpid(domain, cpid),
365
+ eidEvents = await db.readEventsByEid(eid),
366
+ domainEid = await db.readEventsByDomainAndEid(domain, eid),
367
+ scheduledLog = await db.readEventsScheduled()
368
+
369
+ assert.deepEqual(onlineHubs.filter((hub) => hub.id === hubA || hub.id === hubB).map((hub) => hub.id), [ hubA, hubB ])
370
+ assert.deepEqual(eventlog.map((event) => event.id), orderedIDs)
371
+ assert.deepEqual(rangeEvents.map((event) => event.id), orderedIDs)
372
+ assert.deepEqual(namedEvents.map((event) => event.id), orderedIDs)
373
+ assert.deepEqual(cpidEvents.map((event) => event.id), orderedIDs)
374
+ assert.deepEqual(eidEvents.map((event) => event.id), orderedIDs)
375
+ assert.deepEqual(domainEid.map((event) => event.id), orderedIDs)
376
+ assert.deepEqual(scheduledLog.filter((event) => orderedIDs.includes(event.event_id)).map((event) => event.event_id), orderedIDs)
377
+
378
+ await db.updateHubToQuit(hubA)
379
+ await db.updateHubToQuit(hubB)
380
+ await db.deleteEvent(eventA)
381
+ await db.deleteEvent(eventB)
382
+ })
383
+
313
384
  await sub.test('Update hub to quit', async () =>
314
385
  {
315
386
  const updated = await db.updateHubToQuit(hub.id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/eventflow-db",
3
- "version": "4.8.6",
3
+ "version": "4.8.7",
4
4
  "description": "Eventflow db is a set of common database logic in the eventflow ecosystem.",
5
5
  "keywords": [
6
6
  "eventflow"
@@ -14,7 +14,7 @@
14
14
  "scripts": {
15
15
  "test-build": "docker ps -q -f name=eventflow-mysql | grep -q . && docker stop eventflow-mysql; docker run --rm --name eventflow-mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=eventflow -p 3306:3306 --health-cmd=\"mysqladmin ping -h 127.0.0.1 -uroot -proot --silent || exit 1\" --health-interval=10s --health-timeout=5s --health-retries=5 -d mysql:latest; until [ \"$(docker inspect --format='{{.State.Health.Status}}' eventflow-mysql)\" == \"healthy\" ]; do sleep 1; done",
16
16
  "syntax-check": "syntax-check",
17
- "test": "syntax-check; node --test --test-reporter=@superhero/audit/reporter --experimental-test-coverage"
17
+ "test": "syntax-check && node --test --test-reporter=@superhero/audit/reporter --experimental-test-coverage"
18
18
  },
19
19
  "dependencies": {
20
20
  "mysql2": "^3.16.1",
@@ -1,6 +1,8 @@
1
1
  CREATE TABLE IF NOT EXISTS certificate
2
2
  (
3
+ -- TODO: Change Eventflow fractional timestamp columns from DATETIME(3) to DATETIME(6).
3
4
  created DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
5
+ -- TODO: Change Eventflow fractional timestamp columns from DATETIME(3) to DATETIME(6).
4
6
  updated DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
5
7
  version INT UNSIGNED NOT NULL DEFAULT 0,
6
8
  id VARCHAR(64) NOT NULL,
@@ -3,4 +3,6 @@ FROM event
3
3
  WHERE pid = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
4
4
  AND domain = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
5
5
  AND timestamp BETWEEN ? AND ?
6
- ORDER BY timestamp ASC
6
+ ORDER BY
7
+ timestamp ASC,
8
+ id ASC
@@ -3,4 +3,6 @@ FROM event
3
3
  WHERE pid = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
4
4
  AND domain = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
5
5
  AND name IN (?%s)
6
- ORDER BY timestamp ASC
6
+ ORDER BY
7
+ timestamp ASC,
8
+ id ASC
@@ -2,4 +2,6 @@ SELECT *
2
2
  FROM event
3
3
  WHERE pid = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
4
4
  AND domain = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
5
- ORDER BY timestamp ASC
5
+ ORDER BY
6
+ timestamp ASC,
7
+ id ASC
@@ -1,6 +1,7 @@
1
1
  CREATE TABLE IF NOT EXISTS event
2
2
  (
3
3
  id VARCHAR(64) NOT NULL,
4
+ -- TODO: Change Eventflow fractional timestamp columns from DATETIME(3) to DATETIME(6).
4
5
  timestamp DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
5
6
  domain VARCHAR(64) NOT NULL,
6
7
  rid VARCHAR(64) NULL,
@@ -1,10 +1,12 @@
1
1
  SELECT event.*
2
2
  FROM event_cpid
3
3
 
4
- JOIN event
5
- ON event_id = event.id
4
+ JOIN event
5
+ ON event_id = event.id
6
6
 
7
7
  WHERE event_cpid.cpid = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
8
8
  AND event_cpid.domain = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
9
9
 
10
- ORDER BY timestamp ASC
10
+ ORDER BY
11
+ event.timestamp ASC,
12
+ event.id ASC
@@ -1,9 +1,11 @@
1
1
  SELECT event.*
2
2
  FROM event_eid
3
- JOIN event
3
+ JOIN event
4
4
  ON event_id = event.id
5
5
 
6
6
  WHERE eid = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
7
7
  AND domain = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
8
8
 
9
- ORDER BY timestamp ASC
9
+ ORDER BY
10
+ event.timestamp ASC,
11
+ event.id ASC
@@ -1,7 +1,9 @@
1
1
  SELECT event.*
2
2
  FROM event_eid
3
- JOIN event
3
+ JOIN event
4
4
  ON event_id = event.id
5
5
 
6
6
  WHERE eid = CAST(? AS CHAR CHARACTER SET ascii) COLLATE ascii_bin
7
- ORDER BY timestamp ASC
7
+ ORDER BY
8
+ event.timestamp ASC,
9
+ event.id ASC
@@ -2,4 +2,6 @@ SELECT *
2
2
  FROM event_scheduled
3
3
  WHERE scheduled >= UTC_TIMESTAMP()
4
4
  AND executed IS NULL
5
- ORDER BY timestamp ASC
5
+ ORDER BY
6
+ timestamp ASC,
7
+ event_id ASC
@@ -1,4 +1,6 @@
1
1
  SELECT *
2
2
  FROM hub
3
3
  WHERE quit IS NULL
4
- ORDER BY timestamp ASC
4
+ ORDER BY
5
+ timestamp ASC,
6
+ id ASC
@@ -1,5 +1,6 @@
1
1
  CREATE TABLE IF NOT EXISTS log
2
2
  (
3
+ -- TODO: Change Eventflow fractional timestamp columns from DATETIME(3) to DATETIME(6).
3
4
  timestamp DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
4
5
  agent VARCHAR(64) NOT NULL,
5
6
  message TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,