autobahn_client.js
1018 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var WebSocket = require('../lib/faye/websocket'),
pace = require('pace');
var host = 'ws://localhost:9001',
agent = 'Node ' + process.version,
cases = 0,
skip = [];
var socket = new WebSocket.Client(host + '/getCaseCount'),
progress;
socket.onmessage = function(event) {
console.log('Total cases to run: ' + event.data);
cases = parseInt(event.data);
progress = pace(cases);
};
socket.onclose = function() {
var runCase = function(n) {
progress.op();
if (n > cases) {
socket = new WebSocket.Client(host + '/updateReports?agent=' + encodeURIComponent(agent));
socket.onclose = process.exit;
} else if (skip.indexOf(n) >= 0) {
runCase(n + 1);
} else {
socket = new WebSocket.Client(host + '/runCase?case=' + n + '&agent=' + encodeURIComponent(agent));
socket.onmessage = function(event) {
socket.send(event.data);
};
socket.onclose = function() {
runCase(n + 1);
};
}
};
runCase(1);
};