Skip to content

Commit 456c58a

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
[sdk] Properly create/remove CPUThrottlingManager instances in tests
R=kimanh@chromium.org Bug: 490892816 Change-Id: Id134fdb07fa4113fb11b0aa2df92744887527780 Fixed: 491441692 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7653479 Reviewed-by: Kim-Anh Tran <kimanh@chromium.org> Auto-Submit: Simon Zünd <szuend@chromium.org> Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
1 parent 839de3b commit 456c58a

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

front_end/core/sdk/CPUThrottlingManager.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ describeWithMockConnection('CPUThrottlingManager', () => {
2222
return ({getError: () => undefined, result: {value: 42}} as Protocol.Runtime.EvaluateResponse);
2323
});
2424

25-
const manager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance();
25+
const manager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance({forceNew: true});
2626
const concurrency = await manager.getHardwareConcurrency();
2727
assert.strictEqual(concurrency, 42);
2828
});
2929

3030
it('can set the current hardwareConcurrency', async () => {
3131
const cdpStub = sinon.stub(target.emulationAgent(), 'invoke_setHardwareConcurrencyOverride').resolves();
3232

33-
const manager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance();
33+
const manager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance({forceNew: true});
3434
manager.setHardwareConcurrency(5);
3535

3636
sinon.assert.calledOnce(cdpStub);
@@ -40,7 +40,7 @@ describeWithMockConnection('CPUThrottlingManager', () => {
4040
it('does not set concurrency to 0 or negative numbers', async () => {
4141
const cdpStub = sinon.stub(target.emulationAgent(), 'invoke_setHardwareConcurrencyOverride').resolves();
4242

43-
const manager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance();
43+
const manager = SDK.CPUThrottlingManager.CPUThrottlingManager.instance({forceNew: true});
4444
manager.setHardwareConcurrency(0);
4545
sinon.assert.notCalled(cdpStub);
4646

front_end/core/sdk/CPUThrottlingManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const str_ = i18n.i18n.registerUIStrings('core/sdk/CPUThrottlingManager.ts', UIS
3535
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
3636
const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(undefined, str_);
3737

38-
let throttlingManagerInstance: CPUThrottlingManager;
38+
let throttlingManagerInstance: CPUThrottlingManager|undefined;
3939

4040
export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes> implements
4141
SDKModelObserver<EmulationModel> {
@@ -62,6 +62,10 @@ export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper<Eve
6262
return throttlingManagerInstance;
6363
}
6464

65+
static removeInstance(): void {
66+
throttlingManagerInstance = undefined;
67+
}
68+
6569
cpuThrottlingRate(): number {
6670
return this.#cpuThrottlingOption.rate();
6771
}

front_end/testing/EnvironmentHelpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function deinitializeGlobalVars() {
8181
deinitializeGlobalLocaleVars();
8282
Logs.NetworkLog.NetworkLog.removeInstance();
8383
SDK.TargetManager.TargetManager.removeInstance();
84+
SDK.CPUThrottlingManager.CPUThrottlingManager.removeInstance();
8485
SDK.FrameManager.FrameManager.removeInstance();
8586
Common.Settings.Settings.removeInstance();
8687
Common.Revealer.RevealerRegistry.removeInstance();

0 commit comments

Comments
 (0)