Skip to content

Commit dc18923

Browse files
committed
js: In remote.DriverService#start(), short-circuit polling the server status
if the child process dies. Fixes #349
1 parent 47e9ce8 commit dc18923

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

Diff for: javascript/node/selenium-webdriver/CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## v2.46.0-dev
22

3+
* FIXED: `remote.DriverService#start()` will now fail if the child process dies
4+
while waiting for the server to start accepting requests. Previously, start
5+
would continue to poll the server address until the timeout expired.
36
* FIXED: 8564: `firefox.Driver#quit()` will wait for the Firefox process to
47
terminate before deleting the temporary webdriver profile. This eliminates a
58
race condition where Firefox would write profile data during shutdown,

Diff for: javascript/node/selenium-webdriver/remote/index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ DriverService.prototype.start = function(opt_timeoutMs) {
175175

176176
self.command_.fulfill(command);
177177

178-
command.result().then(function(result) {
179-
self.address_.reject(result.code == null ?
178+
var earlyTermination = command.result().then(function(result) {
179+
var error = result.code == null ?
180180
Error('Server was killed with ' + result.signal) :
181-
Error('Server exited with ' + result.code));
181+
Error('Server terminated early with status ' + result.code);
182+
self.address_.reject(error);
182183
self.address_ = null;
183184
self.command_ = null;
185+
throw error;
184186
});
185187

186188
var serverUrl = url.format({
@@ -191,9 +193,15 @@ DriverService.prototype.start = function(opt_timeoutMs) {
191193
pathname: self.path_
192194
});
193195

194-
return httpUtil.waitForServer(serverUrl, timeout).then(function() {
196+
var ready = httpUtil.waitForServer(serverUrl, timeout).then(function() {
195197
return serverUrl;
196198
});
199+
200+
earlyTermination.thenCatch(function(e) {
201+
ready.cancel(e.message);
202+
});
203+
204+
return ready;
197205
});
198206
}));
199207

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2015 Software Freedom Conservancy
2+
// Copyright 2015 Selenium committers
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
var assert = require('assert');
17+
18+
var promise = require('../').promise;
19+
var remote = require('../remote');
20+
21+
describe('DriverService', function() {
22+
23+
describe('start() fails if child-process dies', function() {
24+
var service = new remote.DriverService(process.execPath, {
25+
port: 1234,
26+
args: ['-e', 'process.exit(1)']
27+
})
28+
29+
after(function(done) {
30+
service.kill().thenFinally(function() {
31+
done();
32+
});
33+
});
34+
35+
it('', function(done) {
36+
this.timeout(1000);
37+
service.start(500).then(function() {
38+
done(Error('expected to fail'));
39+
}, function(e) {
40+
try {
41+
assert.equal('Server terminated early with status 1', e.message);
42+
done();
43+
} catch (e) {
44+
done(e);
45+
}
46+
});
47+
});
48+
});
49+
});

0 commit comments

Comments
 (0)