From 476e7806ef40a758dd30703b613e8480a2304bba Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Mon, 27 Mar 2017 17:40:36 -0700 Subject: [PATCH] fix: remove afterPass throttling (#1901) --- lighthouse-core/gather/driver.js | 19 ++++++++-------- lighthouse-core/gather/gather-runner.js | 5 ++++- .../test/gather/gather-runner-test.js | 22 ++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 295733d907b7..3ab0fdeae8ff 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -696,15 +696,16 @@ class Driver { } setThrottling(flags, passConfig) { - const p = []; - if (passConfig.useThrottling) { - if (!flags.disableNetworkThrottling) p.push(emulation.enableNetworkThrottling(this)); - if (!flags.disableCpuThrottling) p.push(emulation.enableCPUThrottling(this)); - } else { - p.push(emulation.disableNetworkThrottling(this)); - p.push(emulation.disableCPUThrottling(this)); - } - return Promise.all(p); + const throttleCpu = passConfig.useThrottling && !flags.disableCpuThrottling; + const throttleNetwork = passConfig.useThrottling && !flags.disableNetworkThrottling; + const cpuPromise = throttleCpu ? + emulation.enableCPUThrottling(this) : + emulation.disableCPUThrottling(this); + const networkPromise = throttleNetwork ? + emulation.enableNetworkThrottling(this) : + emulation.disableNetworkThrottling(this); + + return Promise.all([cpuPromise, networkPromise]); } /** diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 494844156f9b..4faa3809b007 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -47,7 +47,7 @@ const URL = require('../lib/url-shim'); * c. navigate to options.url (and wait for onload) * ii. all gatherer's pass() * C. GatherRunner.afterPass() - * i. endTrace (if requested) & endNetworkCollect + * i. endTrace (if requested) & endNetworkCollect & endThrottling * ii. all gatherer's afterPass() * * 3. Teardown @@ -244,6 +244,9 @@ class GatherRunner { log.verbose('statusEnd', status); }); + // Disable throttling so the afterPass analysis isn't throttled + pass = pass.then(_ => driver.setThrottling(options.flags, {useThrottling: false})); + pass = gatherers.reduce((chain, gatherer) => { const status = `Retrieving: ${gatherer.name}`; return chain.then(_ => { diff --git a/lighthouse-core/test/gather/gather-runner-test.js b/lighthouse-core/test/gather/gather-runner-test.js index eba62c1566a8..bcafa489557f 100644 --- a/lighthouse-core/test/gather/gather-runner-test.js +++ b/lighthouse-core/test/gather/gather-runner-test.js @@ -177,8 +177,8 @@ describe('GatherRunner', function() { calledNetworkEmulation: false, calledCpuEmulation: false, }; - const createEmulationCheck = variable => () => { - tests[variable] = true; + const createEmulationCheck = variable => (...args) => { + tests[variable] = args; return true; }; const driver = getMockedEmulationDriver( @@ -192,9 +192,11 @@ describe('GatherRunner', function() { disableNetworkThrottling: true, } }).then(_ => { - assert.equal(tests.calledDeviceEmulation, true); - assert.equal(tests.calledNetworkEmulation, false); - assert.equal(tests.calledCpuEmulation, true); + assert.ok(tests.calledDeviceEmulation, 'called device emulation'); + assert.deepEqual(tests.calledNetworkEmulation, [{ + latency: 0, downloadThroughput: 0, uploadThroughput: 0, offline: false + }]); + assert.ok(tests.calledCpuEmulation, 'called CPU emulation'); }); }); @@ -204,8 +206,8 @@ describe('GatherRunner', function() { calledNetworkEmulation: false, calledCpuEmulation: false, }; - const createEmulationCheck = variable => () => { - tests[variable] = true; + const createEmulationCheck = variable => (...args) => { + tests[variable] = args; return true; }; const driver = getMockedEmulationDriver( @@ -219,9 +221,9 @@ describe('GatherRunner', function() { disableCpuThrottling: true, } }).then(_ => { - assert.equal(tests.calledDeviceEmulation, true); - assert.equal(tests.calledNetworkEmulation, true); - assert.equal(tests.calledCpuEmulation, false); + assert.ok(tests.calledDeviceEmulation, 'called device emulation'); + assert.ok(tests.calledNetworkEmulation, 'called network emulation'); + assert.deepEqual(tests.calledCpuEmulation, [{rate: 1}]); }); });