Skip to content

Commit

Permalink
fix: remove afterPass throttling (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and brendankenny committed Mar 28, 2017
1 parent 1708865 commit 476e780
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
19 changes: 10 additions & 9 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(_ => {
Expand Down
22 changes: 12 additions & 10 deletions lighthouse-core/test/gather/gather-runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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');
});
});

Expand All @@ -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(
Expand All @@ -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}]);
});
});

Expand Down

0 comments on commit 476e780

Please sign in to comment.