Skip to content

Commit 6d4ea73

Browse files
committed
Update tests for trailing events changes
We no longer keep `glean.restarted` events at the end of the events array, so the tests needed to be updated to reflect that. The tests check everything the same way, they just no longer check that the final item is a `glean.restarted` event.
1 parent c62bffe commit 6d4ea73

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

glean/tests/unit/core/metrics/events_database.spec.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,9 @@ describe("EventsDatabase", function() {
342342
for (const store of stores) {
343343
const snapshot = await db2.getPingEvents(store, true);
344344
assert.ok(snapshot);
345-
assert.strictEqual(2, snapshot.length);
345+
assert.strictEqual(1, snapshot.length);
346346
assert.strictEqual("test", (snapshot[0] as JSONObject)["category"]);
347347
assert.strictEqual("event_injection", (snapshot[0] as JSONObject)["name"]);
348-
assert.strictEqual("glean", (snapshot[1] as JSONObject)["category"]);
349-
assert.strictEqual("restarted", (snapshot[1] as JSONObject)["name"]);
350348

351349
// Check that no errors were recorded for the `glean.restarted` metric.
352350
const restartedMetric = getGleanRestartedEventMetric([store]);
@@ -400,8 +398,13 @@ describe("EventsDatabase", function() {
400398
for (let i = 0; i < 10; i++) {
401399
assert.strictEqual("test", (snapshot[i * 2] as JSONObject)["category"]);
402400
assert.strictEqual(`stichting_test_${i}`, (snapshot[i * 2] as JSONObject)["name"]);
403-
assert.strictEqual("glean", (snapshot[(i * 2) + 1] as JSONObject)["category"]);
404-
assert.strictEqual("restarted", (snapshot[(i * 2) + 1] as JSONObject)["name"]);
401+
402+
// We no longer keep trailing restarted events, so in this scenario, we need to ignore
403+
// the final element of the snapshot since it previously had a restarted event.
404+
if (snapshot[(i * 2) + 1]) {
405+
assert.strictEqual("glean", (snapshot[(i * 2) + 1] as JSONObject)["category"]);
406+
assert.strictEqual("restarted", (snapshot[(i * 2) + 1] as JSONObject)["name"]);
407+
}
405408

406409
// Check that no errors were recorded for the `glean.restarted` metric.
407410
const restartedMetric = getGleanRestartedEventMetric(["store"]);
@@ -455,8 +458,13 @@ describe("EventsDatabase", function() {
455458
for (let i = 0; i < 10; i++) {
456459
assert.strictEqual("test", (snapshot[i * 2] as JSONObject)["category"]);
457460
assert.strictEqual(`time_travel_${i}`, (snapshot[i * 2] as JSONObject)["name"]);
458-
assert.strictEqual("glean", (snapshot[(i * 2) + 1] as JSONObject)["category"]);
459-
assert.strictEqual("restarted", (snapshot[(i * 2) + 1] as JSONObject)["name"]);
461+
462+
// We no longer keep trailing restarted events, so in this scenario, we need to ignore
463+
// the final element of the snapshot since it previously had a restarted event.
464+
if (snapshot[(i * 2) + 1]) {
465+
assert.strictEqual("glean", (snapshot[(i * 2) + 1] as JSONObject)["category"]);
466+
assert.strictEqual("restarted", (snapshot[(i * 2) + 1] as JSONObject)["name"]);
467+
}
460468
}
461469

462470
// Time went backwards, so errors must have been recorded.
@@ -509,8 +517,13 @@ describe("EventsDatabase", function() {
509517
for (let i = 0; i < 10; i++) {
510518
assert.strictEqual("test", (snapshot[i * 2] as JSONObject)["category"]);
511519
assert.strictEqual(`time_travel_${i}`, (snapshot[i * 2] as JSONObject)["name"]);
512-
assert.strictEqual("glean", (snapshot[(i * 2) + 1] as JSONObject)["category"]);
513-
assert.strictEqual("restarted", (snapshot[(i * 2) + 1] as JSONObject)["name"]);
520+
521+
// We no longer keep trailing restarted events, so in this scenario, we need to ignore
522+
// the final element of the snapshot since it previously had a restarted event.
523+
if (snapshot[(i * 2) + 1]) {
524+
assert.strictEqual("glean", (snapshot[(i * 2) + 1] as JSONObject)["category"]);
525+
assert.strictEqual("restarted", (snapshot[(i * 2) + 1] as JSONObject)["name"]);
526+
}
514527
}
515528

516529
// Time stood still, so an error must have been recorded.

0 commit comments

Comments
 (0)