Skip to content

Commit

Permalink
Eliminate errors from calling ChromeLauncher.kill() twice (GoogleChro…
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored and andrewrota committed Jan 13, 2017
1 parent b9176a4 commit 4dfa8f2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lighthouse-cli/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class ChromeLauncher {
if (process.platform === 'win32') {
spawnSync(`taskkill /pid ${this.chrome.pid} /T /F`);
}
this.chrome = null;
} else {
// fail silently as we did not start chrome
resolve();
Expand All @@ -227,24 +228,24 @@ class ChromeLauncher {
}

destroyTmp(): Promise<undefined> {
if (!this.TMP_PROFILE_DIR) {
return Promise.resolve();
}
return new Promise(resolve => {
if (!this.TMP_PROFILE_DIR) {
return resolve();
}

log.verbose('ChromeLauncher', `Removing ${this.TMP_PROFILE_DIR}`);
log.verbose('ChromeLauncher', `Removing ${this.TMP_PROFILE_DIR}`);

if (this.outFile) {
fs.closeSync(this.outFile);
}
if (this.outFile) {
fs.closeSync(this.outFile);
this.outFile = null;
}

if (this.errFile) {
fs.closeSync(this.errFile);
}
if (this.errFile) {
fs.closeSync(this.errFile);
this.errFile = null;
}

return new Promise((resolve) => {
rimraf(this.TMP_PROFILE_DIR, function() {
resolve();
});
rimraf(this.TMP_PROFILE_DIR, () => resolve());
});
}
};
Expand Down
36 changes: 36 additions & 0 deletions lighthouse-cli/test/cli/chrome-launcher-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2016 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

require('../../compiled-check.js')('chrome-launcher.js');

const ChromeLauncher = require('../../chrome-launcher.js').ChromeLauncher;

/* eslint-env mocha */

describe('ChromeLauncher', () => {
it('doesn\'t fail when killed twice', () => {
const chromeInstance = new ChromeLauncher();
return chromeInstance.run()
.then(() => {
return Promise.all([
chromeInstance.kill(),
chromeInstance.kill()
]);
});
});
});

0 comments on commit 4dfa8f2

Please sign in to comment.