Skip to content

Commit d2186d6

Browse files
Doctor: use exit code to indicate success/failure
1 parent 1c16c63 commit d2186d6

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/main/java/com/testingbot/tunnel/App.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ public static void main(String... args) throws Exception {
168168
String clientKey = null;
169169
String clientSecret = null;
170170

171+
if (commandLine.hasOption("se-port")) {
172+
app.seleniumPort = Integer.parseInt(commandLine.getOptionValue("se-port"));
173+
}
174+
175+
if (commandLine.hasOption("localproxy")) {
176+
app.setJettyPort(Integer.parseInt(commandLine.getOptionValue("localproxy")));
177+
} else {
178+
app.setFreeJettyPort();
179+
}
180+
171181
if (commandLine.hasOption("doctor")) {
172182
app.doctor();
173183
return;
@@ -256,12 +266,6 @@ public static void main(String... args) throws Exception {
256266
app.pac = commandLine.getOptionValue("pac");
257267
}
258268

259-
if (commandLine.hasOption("localproxy")) {
260-
app.setJettyPort(Integer.parseInt(commandLine.getOptionValue("localproxy")));
261-
} else {
262-
app.setFreeJettyPort();
263-
}
264-
265269
if (commandLine.hasOption("readyfile")) {
266270
app.readyFile = commandLine.getOptionValue("readyfile").trim();
267271
}
@@ -292,10 +296,6 @@ public static void main(String... args) throws Exception {
292296
LocalWebServer local = new LocalWebServer(commandLine.getOptionValue("web"));
293297
}
294298

295-
if (commandLine.hasOption("se-port")) {
296-
app.seleniumPort = Integer.parseInt(commandLine.getOptionValue("se-port"));
297-
}
298-
299299
app.init();
300300
app.boot();
301301
} catch (ParseException parseException) {
@@ -476,6 +476,9 @@ private void startProxies() {
476476

477477
public void doctor() {
478478
Doctor doctor = new Doctor(this);
479+
if (doctor.hasFailures()) {
480+
System.exit(1);
481+
}
479482
}
480483

481484
public HttpProxy getHttpProxy() {

src/main/java/com/testingbot/tunnel/Doctor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
* @author testingbot
3333
*/
3434
public final class Doctor {
35-
3635
private final App app;
36+
private boolean hasFailures = false;
37+
3738
public Doctor(App app) {
3839
this.app = app;
3940
app.setFreeJettyPort();
@@ -45,18 +46,24 @@ public Doctor(App app) {
4546
uris.add(new URI("https://www.google.com/"));
4647
} catch (URISyntaxException e) {
4748
Logger.getLogger(Doctor.class.getName()).log(Level.SEVERE, e.getMessage());
49+
hasFailures = true;
4850
}
4951

5052
performChecks(uris);
5153
}
5254

55+
public boolean hasFailures() {
56+
return hasFailures;
57+
}
58+
5359
public void performChecks(ArrayList<URI> uris) {
5460
try {
5561
for (URI uri : uris) {
5662
performCheck(uri);
5763
}
5864
} catch (UnknownHostException e) {
5965
Logger.getLogger(Doctor.class.getName()).log(Level.SEVERE, e.getMessage());
66+
hasFailures = true;
6067
}
6168

6269
checkOpenPorts();
@@ -67,13 +74,15 @@ public void checkOpenPorts() {
6774
boolean canOpenJetty = checkPortOpen(app.getJettyPort());
6875
if (!canOpenJetty) {
6976
Logger.getLogger(Doctor.class.getName()).log(Level.SEVERE, "Cannot open proxy port {0}.\nDoes this process have the correct permissions?", Integer.toString(app.getJettyPort()));
77+
hasFailures = true;
7078
} else {
7179
Logger.getLogger(Doctor.class.getName()).log(Level.INFO, "OK - Proxy port {0} can be opened", Integer.toString(app.getJettyPort()));
7280
}
7381

7482
boolean canOpenSEPort = checkPortOpen(app.getSeleniumPort());
7583
if (!canOpenSEPort) {
7684
Logger.getLogger(Doctor.class.getName()).log(Level.SEVERE, "Cannot open Selenium port {0}.\nPerhaps another process is using this port? Or this process does not have the correct permission?", Integer.toString(app.getSeleniumPort()));
85+
hasFailures = true;
7786
} else {
7887
Logger.getLogger(Doctor.class.getName()).log(Level.INFO, "OK - Selenium port {0} can be opened", Integer.toString(app.getSeleniumPort()));
7988
}
@@ -96,6 +105,7 @@ public void performCheck(final URI uri) throws UnknownHostException {
96105
Logger.getLogger(Doctor.class.getName()).log(Level.INFO, "OK - URL {0} can be reached.", uri.toString());
97106
} else {
98107
Logger.getLogger(Doctor.class.getName()).log(Level.SEVERE, "URL {0} can not be reached.", uri.toString());
108+
hasFailures = true;
99109
}
100110
}
101111

0 commit comments

Comments
 (0)