Skip to content

Commit 065facb

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[unittest] Fix out of memory error
This CL resets the TraceLoader caches after each describe that was attached on the global scope this usally means one reset per file but if you have describe('A'); describe('B'); on the top level of one file it will rest 2 times. Because we were never clearing this at one point we ended up with over 3GB on the heap. Bug: none Change-Id: I267faf321c0ad136f194db26bcca3ef08469464d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6917688 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
1 parent 7a5ccd4 commit 065facb

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

front_end/testing/TraceLoader.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ export class TraceLoader {
284284
const traceContents = JSON.parse(contents) as Trace.Types.File.TraceFile;
285285
return traceContents;
286286
}
287+
288+
/**
289+
* Karma test run in a single context if we load all the traces
290+
* we risk getting out of memory
291+
*/
292+
static resetCache() {
293+
fileContentsCache.clear();
294+
traceEngineCache.clear();
295+
}
287296
}
288297

289298
export async function fetchFileAsText(url: URL): Promise<string> {

front_end/testing/test_setup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as ThemeSupport from '../ui/legacy/theme_support/theme_support.js';
1717

1818
import {cleanTestDOM, raf, setupTestDOM} from './DOMHelpers.js';
1919
import {createFakeSetting, resetHostConfig} from './EnvironmentHelpers.js';
20+
import {TraceLoader} from './TraceLoader.js';
2021
import {
2122
checkForPendingActivity,
2223
startTrackingAsyncActivity,
@@ -32,7 +33,7 @@ document.documentElement.classList.add('platform-screenshot-test');
3233
const documentBodyElements = new Set<Element>();
3334

3435
// Warm-up fonts to be readily available.
35-
before(async () => {
36+
before(async function() {
3637
const div = document.createElement('div');
3738
div.style.fontFamily = 'roboto';
3839
// Some latin characters to trigger the latin font file to be loaded.
@@ -42,6 +43,15 @@ before(async () => {
4243
document.body.append(div);
4344
await document.fonts.ready;
4445
div.remove();
46+
47+
// There is no way to provide after each file run via a test set up file.
48+
// What we do instead is add and after all in all global test suits
49+
// This is as close as we can get to after each file.
50+
this.test?.parent?.suites.forEach(function(suite) {
51+
suite.afterAll(function() {
52+
TraceLoader.resetCache();
53+
});
54+
});
4555
});
4656

4757
beforeEach(async () => {

0 commit comments

Comments
 (0)