Skip to content

Commit 1f01665

Browse files
committed
ping_type & worker tests
1 parent 7c4db35 commit 1f01665

File tree

5 files changed

+389
-654
lines changed

5 files changed

+389
-654
lines changed

glean/src/core/pings/ping_type.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ export class InternalPingType implements CommonPingData {
114114
}
115115

116116
/// TESTING ///
117-
// TODO
118-
// Does this need to go away?
119-
testBeforeNextSubmit(callbackFn: ValidatorFunction): void {
117+
async testBeforeNextSubmit(callbackFn: ValidatorFunction): Promise<void> {
120118
if (testOnlyCheck("testBeforeNextSubmit", LOG_TAG)) {
121119
if (this.testCallback) {
122120
log(
@@ -127,7 +125,11 @@ export class InternalPingType implements CommonPingData {
127125
return;
128126
}
129127

130-
this.testCallback = callbackFn;
128+
return new Promise((resolve, reject) => {
129+
this.resolveTestPromiseFunction = resolve;
130+
this.rejectTestPromiseFunction = reject;
131+
this.testCallback = callbackFn;
132+
});
131133
}
132134
}
133135
}
@@ -161,8 +163,6 @@ export default class {
161163
this.#inner.submit(reason);
162164
}
163165

164-
// TODO
165-
// Does this need to go away?
166166
/**
167167
* Test-only API
168168
*
@@ -173,7 +173,7 @@ export default class {
173173
* @returns A `Promise` resolved when the ping is collected and the validation function
174174
* is executed.
175175
*/
176-
testBeforeNextSubmit(callbackFn: ValidatorFunction): void {
176+
testBeforeNextSubmit(callbackFn: ValidatorFunction): Promise<void> {
177177
return this.#inner.testBeforeNextSubmit(callbackFn);
178178
}
179179
}

glean/src/core/upload/worker.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,35 @@ class PingUploadWorker {
130130
getUploadTask: () => UploadTask,
131131
processUploadResponse: (ping: QueuedPing, result: UploadResult) => void
132132
): void {
133-
try {
134-
const task = getUploadTask();
135-
switch (task.type) {
136-
case UploadTaskTypes.Upload:
137-
if (this.isBlocking) {
138-
return;
133+
while (true) {
134+
try {
135+
const task = getUploadTask();
136+
switch (task.type) {
137+
case UploadTaskTypes.Upload: {
138+
if (this.isBlocking) {
139+
return;
140+
}
141+
142+
this.attemptPingUpload(task.ping)
143+
.then((result) => {
144+
processUploadResponse(task.ping, result);
145+
})
146+
.catch((error) => {
147+
console.log(error);
148+
});
149+
continue;
139150
}
140151

141-
this.attemptPingUpload(task.ping)
142-
.then((result) => {
143-
processUploadResponse(task.ping, result);
144-
})
145-
.catch((error) => {
146-
console.log(error);
147-
});
152+
case UploadTaskTypes.Done:
153+
return;
154+
}
155+
} catch (error) {
156+
log(
157+
PING_UPLOAD_WORKER_LOG_TAG,
158+
["IMPOSSIBLE: Something went wrong while processing ping upload tasks.", error],
159+
LoggingLevel.Error
160+
);
148161
}
149-
} catch (error) {
150-
log(
151-
PING_UPLOAD_WORKER_LOG_TAG,
152-
["IMPOSSIBLE: Something went wrong while processing ping upload tasks.", error],
153-
LoggingLevel.Error
154-
);
155162
}
156163
}
157164

0 commit comments

Comments
 (0)