Skip to content

Commit 3443a2d

Browse files
committed
add a small timeout to initial IP probing
1 parent 2d377fc commit 3443a2d

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

main-view-model.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ export class TestBrokerViewModel extends observable.Observable {
9595
var foundKarma = false;
9696
var resolvers = config.ips.map(ip => {
9797
var karmaClientUrl = 'http://' + ip + ':' + config.port + '/context.json';
98-
console.log('UTR: fetching ' + karmaClientUrl);
99-
return http.getString(karmaClientUrl)
100-
.then(() => {
101-
console.log('UTR: got something from ' + ip);
98+
console.log('NSUTR: fetching ' + karmaClientUrl);
99+
return http.getString({
100+
url: karmaClientUrl,
101+
method: 'GET',
102+
timeout: 3000,
103+
}).then(() => {
104+
console.log('NSUTR: found karma at ' + ip);
102105
if (!foundKarma) {
103106
foundKarma = true;
104107
resolve(ip);
@@ -115,8 +118,6 @@ export class TestBrokerViewModel extends observable.Observable {
115118

116119
return successfulResolution
117120
.then(result => {
118-
console.log('UTR: and the results are in...');
119-
120121
if (result) {
121122
this.set('serverInfo', 'found karma at ' + result);
122123
this.networkConfig.reachableIp = result;
@@ -130,16 +131,16 @@ export class TestBrokerViewModel extends observable.Observable {
130131
return err => {
131132
this.set('serverInfo', message);
132133
if (err) {
133-
console.log('socket.io: ' + err.toString());
134+
console.log('NSUTR-socket.io: ' + err.toString());
134135
}
135136
}
136137
}
137138

138139
public connectToKarma() {
139-
console.log('UTR: connecting to karma');
140+
this.baseUrl = 'http://' + this.networkConfig.reachableIp + ':' + this.networkConfig.port;
141+
console.log('NSUTR: connecting to karma at ' + this.baseUrl);
140142

141143
var io = require('./socket.io');
142-
this.baseUrl = 'http://' + this.networkConfig.reachableIp + ':' + this.networkConfig.port;
143144
this.set('serverInfo', 'connecting to ' + this.baseUrl);
144145
var socket = this.socket = io.connect(this.baseUrl, {
145146
forceBase64: true
@@ -152,7 +153,7 @@ export class TestBrokerViewModel extends observable.Observable {
152153
var connected = this.updateBanner('connected');
153154

154155
socket.on('connect', err => {
155-
console.log('UTR: connected to karma!!!');
156+
console.log('UTR: successfully connected to karma');
156157

157158
connected();
158159

@@ -171,7 +172,7 @@ export class TestBrokerViewModel extends observable.Observable {
171172
socket.on('connect_failed', this.updateBanner('connection failed'));
172173
socket.on('disconnect', () => this.updateBrowsersInfo([]));
173174

174-
socket.on('connect_error', data => console.log('socket.io error on connect: ' + data));
175+
socket.on('connect_error', data => console.log('NSUTR: socket.io error on connect: ' + data));
175176

176177
socket.on('execute', this.onKarmaExecute.bind(this));
177178
}
@@ -195,7 +196,7 @@ export class TestBrokerViewModel extends observable.Observable {
195196

196197
public executeTestRun() {
197198
if (this.executed) {
198-
console.log('disregarding second execution');
199+
console.log('NSUTR: disregarding second execution');
199200
return;
200201
}
201202
this.executed = true;
@@ -205,7 +206,7 @@ export class TestBrokerViewModel extends observable.Observable {
205206
this.startEmitted = false;
206207
this.hasError = false;
207208
var contextUrl = this.baseUrl + '/context.json';
208-
console.log("Downloading " + contextUrl);
209+
console.log("NSUTR: downloading " + contextUrl);
209210
http.getString(contextUrl)
210211
.then(content => {
211212
var parsedContent: IKarmaContext = JSON.parse(content);
@@ -238,10 +239,10 @@ export class TestBrokerViewModel extends observable.Observable {
238239
public runTests(testScripts) {
239240
testScripts.forEach((script, i) => {
240241
if (script.localPath) {
241-
console.log('require script ' + script.url + ' from ' + script.localPath);
242+
console.log('NSUTR: require script ' + script.url + ' from ' + script.localPath);
242243
require(script.localPath);
243244
} else {
244-
console.log('eval script ' + script.url);
245+
console.log('NSUTR: eval script ' + script.url);
245246
this.loadShim(script.url);
246247
//call eval indirectly to execute the scripts in the global scope
247248
var geval = eval;
@@ -293,13 +294,13 @@ export class TestBrokerViewModel extends observable.Observable {
293294
}
294295

295296
public complete(data?: any) {
296-
console.log("Completed test run.");
297+
console.log("NSUTR: completed test run.");
297298
this.set('testsRunning', false);
298299

299300
delete this.start;
300301

301302
this.socketEmit('complete', data || {}, () => {
302-
console.log('completeAck');
303+
console.log('NSUTR: completeAck');
303304
this.socketEmit('disconnect');
304305
setTimeout(() => stopProcess(), 500);
305306
});
@@ -308,7 +309,7 @@ export class TestBrokerViewModel extends observable.Observable {
308309
public error(msg: string, url?: string, line?: number) {
309310
this.hasError = true;
310311
var fullMsg = url ? msg + '\nat ' + url + (line ? ':' + line : '') : msg;
311-
console.log("this.error: " + fullMsg);
312+
console.log("NSUTR: this.error: " + fullMsg);
312313
this.socketEmit('error', fullMsg);
313314
this.complete();
314315
return false;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-unit-test-runner",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "NativeScript unit test runner component.",
55
"main": "app.js",
66
"scripts": {

0 commit comments

Comments
 (0)