Skip to content

Commit 75a9888

Browse files
committed
Update unit/core tests
1 parent 7536c76 commit 75a9888

File tree

4 files changed

+120
-297
lines changed

4 files changed

+120
-297
lines changed

glean/tests/unit/core/context.spec.ts

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,39 @@
55
import assert from "assert";
66

77
import { Context } from "../../../src/core/context";
8-
import Dispatcher from "../../../src/core/dispatcher";
9-
import Glean from "../../../src/core/glean/async";
10-
import MetricsDatabase from "../../../src/core/metrics/database/async";
11-
import EventsDatabase from "../../../src/core/metrics/events_database/async";
12-
import PingsDatabase from "../../../src/core/pings/database/async";
8+
import Glean from "../../../src/core/glean";
9+
import MetricsDatabase from "../../../src/core/metrics/database";
10+
import EventsDatabase from "../../../src/core/metrics/events_database";
11+
import PingsDatabase from "../../../src/core/pings/database";
1312
import { testResetGlean } from "../../../src/core/testing";
1413
import { testUninitializeGlean } from "../../../src/core/testing/utils";
1514
import { sanitizeApplicationId } from "../../../src/core/utils";
1615

1716
describe("Context", function() {
1817
const testAppId = `gleanjs.test.${this.title}`;
1918

20-
beforeEach(async function () {
21-
await testResetGlean(testAppId);
19+
beforeEach(function () {
20+
testResetGlean(testAppId);
2221
});
2322

24-
it("dispatcher contains the expected value", async function () {
25-
assert.notStrictEqual(Context.dispatcher, undefined);
26-
assert.ok(Context.dispatcher instanceof Dispatcher);
27-
28-
await testUninitializeGlean();
29-
// Dispatcher should be available when Glean is uninitialized too.
30-
assert.notStrictEqual(Context.dispatcher, undefined);
31-
assert.ok((Context.dispatcher as unknown) instanceof Dispatcher);
32-
});
33-
34-
it("uploadEnabled contains the expected value", async function () {
23+
it("uploadEnabled contains the expected value", function () {
3524
assert.strictEqual(Context.uploadEnabled, true);
3625

3726
Glean.setUploadEnabled(false);
38-
await Context.dispatcher.testBlockOnQueue();
3927
assert.strictEqual(Context.uploadEnabled, false);
4028
});
4129

42-
it("appId contains the expected value", async function () {
30+
it("appId contains the expected value", function () {
4331
assert.strictEqual(Context.applicationId, sanitizeApplicationId(testAppId));
4432

45-
await testResetGlean("new-id");
33+
testResetGlean("new-id");
4634
assert.strictEqual(Context.applicationId, sanitizeApplicationId("new-id"));
4735
});
4836

49-
it("initialized contains the expected value", async function () {
37+
it("initialized contains the expected value", function () {
5038
assert.strictEqual(Context.initialized, true);
5139

52-
await testUninitializeGlean();
40+
testUninitializeGlean();
5341
assert.strictEqual(Context.initialized, false);
5442
});
5543

@@ -63,20 +51,4 @@ describe("Context", function() {
6351
assert.notStrictEqual(Context.pingsDatabase, undefined);
6452
assert.ok(Context.pingsDatabase instanceof PingsDatabase);
6553
});
66-
67-
it("the dispatcher is always available", function () {
68-
const originalDispatcher = Context.dispatcher;
69-
assert.notStrictEqual(originalDispatcher, null);
70-
71-
Context.testUninitialize();
72-
73-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
74-
// @ts-ignore
75-
assert.strictEqual(Context._instance?._dispatcher, undefined);
76-
77-
// Trying to access the dispatcher will instantiate a new one.
78-
const newDispatcher = Context.instance;
79-
assert.notStrictEqual(newDispatcher, null);
80-
assert.notStrictEqual(newDispatcher, originalDispatcher);
81-
});
8254
});

glean/tests/unit/core/error_recording.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import { combineIdentifierAndLabel } from "../../../src/core/metrics/types/label
1414
describe("error_recording", function() {
1515
const testAppId = `gleanjs.test.${this.title}`;
1616

17-
beforeEach(async function() {
18-
await testResetGlean(testAppId);
17+
beforeEach(function() {
18+
testResetGlean(testAppId);
1919
});
2020

21-
it("records error types correctly", async function () {
21+
it("records error types correctly", function () {
2222
const metric = new StringMetricType({
2323
category: "aCategory",
2424
name: "aStringMetric",
@@ -27,14 +27,14 @@ describe("error_recording", function() {
2727
disabled: false
2828
});
2929

30-
await Context.errorManager.record(metric, ErrorType.InvalidValue, "Invalid value");
31-
await Context.errorManager.record(metric, ErrorType.InvalidLabel, "Invalid label", 10);
30+
Context.errorManager.record(metric, ErrorType.InvalidValue, "Invalid value");
31+
Context.errorManager.record(metric, ErrorType.InvalidLabel, "Invalid label", 10);
3232

33-
assert.strictEqual(await Context.errorManager.testGetNumRecordedErrors(metric, ErrorType.InvalidValue), 1);
34-
assert.strictEqual(await Context.errorManager.testGetNumRecordedErrors(metric, ErrorType.InvalidLabel), 10);
33+
assert.strictEqual(Context.errorManager.testGetNumRecordedErrors(metric, ErrorType.InvalidValue), 1);
34+
assert.strictEqual(Context.errorManager.testGetNumRecordedErrors(metric, ErrorType.InvalidLabel), 10);
3535
});
3636

37-
it("strips label when recording error to metric that contains label in it's name", async function () {
37+
it("strips label when recording error to metric that contains label in it's name", function () {
3838
// Cannot use the LabeledMetricType here,
3939
// because it does not expose the internal metric types.
4040
const metric: Record<string, StringMetricType> = {
@@ -70,10 +70,10 @@ describe("error_recording", function() {
7070

7171
// When the metric is created from a static label, it will contain the label in it's name,
7272
// otherwise the label stays underd the `dynamicLabel` property.
73-
await Context.errorManager.record(metric.oneLabel, ErrorType.InvalidValue, "Invalid value");
74-
await Context.errorManager.record(metric.anotherLabel, ErrorType.InvalidLabel, "Invalid label", 10);
73+
Context.errorManager.record(metric.oneLabel, ErrorType.InvalidValue, "Invalid value");
74+
Context.errorManager.record(metric.anotherLabel, ErrorType.InvalidLabel, "Invalid label", 10);
7575

76-
assert.strictEqual(await Context.errorManager.testGetNumRecordedErrors(metric.dynamicLabel, ErrorType.InvalidValue), 1);
77-
assert.strictEqual(await Context.errorManager.testGetNumRecordedErrors(metric.dynamicLabel, ErrorType.InvalidLabel), 10);
76+
assert.strictEqual(Context.errorManager.testGetNumRecordedErrors(metric.dynamicLabel, ErrorType.InvalidValue), 1);
77+
assert.strictEqual(Context.errorManager.testGetNumRecordedErrors(metric.dynamicLabel, ErrorType.InvalidLabel), 10);
7878
});
7979
});

glean/tests/unit/core/events.spec.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)