Skip to content

Commit a3c4d57

Browse files
committed
ping_type & worker tests
1 parent d74e7cd commit a3c4d57

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
@@ -108,9 +108,7 @@ export class InternalPingType implements CommonPingData {
108108
}
109109

110110
/// TESTING ///
111-
// TODO
112-
// Does this need to go away?
113-
testBeforeNextSubmit(callbackFn: ValidatorFunction): void {
111+
async testBeforeNextSubmit(callbackFn: ValidatorFunction): Promise<void> {
114112
if (testOnlyCheck("testBeforeNextSubmit", LOG_TAG)) {
115113
if (this.testCallback) {
116114
log(
@@ -121,7 +119,11 @@ export class InternalPingType implements CommonPingData {
121119
return;
122120
}
123121

124-
this.testCallback = callbackFn;
122+
return new Promise((resolve, reject) => {
123+
this.resolveTestPromiseFunction = resolve;
124+
this.rejectTestPromiseFunction = reject;
125+
this.testCallback = callbackFn;
126+
});
125127
}
126128
}
127129
}
@@ -155,8 +157,6 @@ export default class {
155157
this.#inner.submit(reason);
156158
}
157159

158-
// TODO
159-
// Does this need to go away?
160160
/**
161161
* Test-only API
162162
*
@@ -167,7 +167,7 @@ export default class {
167167
* @returns A `Promise` resolved when the ping is collected and the validation function
168168
* is executed.
169169
*/
170-
testBeforeNextSubmit(callbackFn: ValidatorFunction): void {
170+
testBeforeNextSubmit(callbackFn: ValidatorFunction): Promise<void> {
171171
return this.#inner.testBeforeNextSubmit(callbackFn);
172172
}
173173
}

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)