Skip to content

Commit 04cb086

Browse files
sethbrenithDevtools-frontend LUCI CQ
authored andcommitted
Fix heapSnapshotLoaderTest, part 1
The function heapSnapshotLoaderTest, defined in Blink, is async, but the calling code doesn't await its result, so that test has been failing silently for a long time. This change is the DevTools part of fixing it. Bug: 402327008 Change-Id: I348910f1827ed176e886f5310e600cfd50c9e028 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6344191 Commit-Queue: Seth Brenith <[email protected]> Reviewed-by: Simon Zünd <[email protected]>
1 parent bb976f7 commit 04cb086

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,6 @@ export abstract class HeapSnapshot {
937937
this.buildSamples();
938938
this.#progress.updateStatus('Building locations…');
939939
this.buildLocationMap();
940-
this.#progress.updateStatus('Finished processing.');
941940

942941
if (this.profile.snapshot.trace_function_count) {
943942
this.#progress.updateStatus('Building allocation statistics…');
@@ -962,8 +961,9 @@ export abstract class HeapSnapshot {
962961
stats.ids.push(node.id());
963962
}
964963
this.#allocationProfile = new AllocationProfile(this.profile, liveObjects);
965-
this.#progress.updateStatus('done');
966964
}
965+
966+
this.#progress.updateStatus('Finished processing.');
967967
}
968968

969969
private buildEdgeIndexes(): void {

front_end/entrypoints/heap_snapshot_worker/HeapSnapshotLoader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ export class HeapSnapshotLoader {
4545
#array!: Platform.TypedArrayUtilities.BigUint32Array|null;
4646
#arrayIndex!: number;
4747
#json = '';
48+
parsingComplete: Promise<void>;
4849
constructor(dispatcher: HeapSnapshotWorkerDispatcher) {
4950
this.#reset();
5051
this.#progress = new HeapSnapshotProgress(dispatcher);
5152
this.#buffer = [];
5253
this.#dataCallback = null;
5354
this.#done = false;
54-
void this.#parseInput();
55+
this.parsingComplete = this.#parseInput();
5556
}
5657

5758
dispose(): void {
@@ -254,7 +255,7 @@ export class HeapSnapshotLoader {
254255
const stringsTokenIndex = await this.#findToken('"strings"');
255256
const bracketIndex = await this.#findToken('[', stringsTokenIndex);
256257
this.#json = this.#json.slice(bracketIndex);
257-
while (!this.#done) {
258+
while (this.#buffer.length > 0 || !this.#done) {
258259
this.#json += await this.#fetchChunk();
259260
}
260261
this.#parseStringsArray();

front_end/entrypoints/heap_snapshot_worker/HeapSnapshotWorkerDispatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class HeapSnapshotWorkerDispatcher {
5959
this.#postMessage({eventName: name, data});
6060
}
6161

62-
dispatchMessage({data}: {data: HeapSnapshotModel.HeapSnapshotModel.WorkerCommand}): void {
62+
async dispatchMessage({data}: {data: HeapSnapshotModel.HeapSnapshotModel.WorkerCommand}): Promise<void> {
6363
const response: DispatcherResponse =
6464
{callId: data.callId, result: null, error: undefined, errorCallStack: undefined, errorMethodName: undefined};
6565
try {
@@ -102,7 +102,7 @@ export class HeapSnapshotWorkerDispatcher {
102102
};
103103
// @ts-expect-error
104104
globalThis.HeapSnapshotModel = HeapSnapshotModel;
105-
response.result = self.eval(data.source);
105+
response.result = await self.eval(data.source);
106106
} catch (error) {
107107
response.result = error.toString();
108108
}

front_end/legacy_test_runner/heap_profiler_test_runner/heap_profiler_test_runner.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ HeapProfilerTestRunner.createHeapSnapshotMockFactories = function() {
5959
trace_node_fields: ['id', 'function_info_index', 'count', 'size', 'children']
6060
},
6161
node_count: 6,
62-
edge_count: 7
62+
edge_count: 7,
63+
trace_function_count: 1
6364
},
6465

6566
nodes: [
@@ -82,6 +83,9 @@ HeapProfilerTestRunner.createHeapSnapshotMockFactories = function() {
8283
HeapProfilerTestRunner.postprocessHeapSnapshotMock = function(mock) {
8384
mock.nodes = new Uint32Array(mock.nodes);
8485
mock.edges = new Uint32Array(mock.edges);
86+
if (mock.trace_function_infos) {
87+
mock.trace_function_infos = new Uint32Array(mock.trace_function_infos);
88+
}
8589
mock.nodes.getValue = mock.edges.getValue = function(i) {
8690
return this[i];
8791
};

0 commit comments

Comments
 (0)