forked from gwicke/testreduce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·297 lines (251 loc) · 7.25 KB
/
server.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/env node
( function () {
"use strict";
var express = require( 'express' ),
optimist = require( 'optimist' ),
hbs = require( 'handlebars' );
// Default options
var defaults = {
'host': 'localhost',
'port': 3306,
'database': 'parsoid',
'user': 'parsoid',
'password': 'parsoidpw',
'debug': false,
'fetches': 6,
'tries': 6,
'cutofftime': 600,
'batch': 50
};
// Command line options
// These will have to be modified to reflect new cassandra backend
var argv = optimist.usage( 'Usage: $0 [connection parameters]' )
.options( 'help', {
'boolean': true,
'default': false,
describe: "Show usage information."
} )
.options( 'h', {
alias: 'host',
describe: 'Hostname of the database server.'
} )
.options( 'P', {
alias: 'port',
describe: 'Port number to use for connection.'
} )
.options( 'D', {
alias: 'database',
describe: 'Database to use.'
} )
.options( 'u', {
alias: 'user',
describe: 'User for MySQL login.'
} )
.options( 'p', {
alias: 'password',
describe: 'Password.'
} )
.options( 'd', {
alias: 'debug',
'boolean': true,
describe: "Output MySQL debug data."
} )
.options( 'f', {
alias: 'fetches',
describe: "Number of times to try fetching a page."
} )
.options( 't', {
alias: 'tries',
describe: "Number of times an article will be sent for testing " +
"before it's considered an error."
} )
.options( 'c', {
alias: 'cutofftime',
describe: "Time in seconds to wait for a test result."
} )
.options( 'config', {
describe: "Config file path"
} )
.options( 'b', {
alias: 'batch',
describe: "Number of titles to fetch from database in one batch."
} )
.argv;
if ( argv.help ) {
optimist.showHelp();
process.exit( 0 );
}
// Settings file
var settings;
try {
var settingsPath = argv.config || './server.settings.js';
settings = require( settingsPath );
} catch ( e ) {
settings = {};
}
var getOption = function( opt ) {
var value;
// Check possible options in this order: command line, settings file, defaults.
if ( argv.hasOwnProperty( opt ) ) {
value = argv[ opt ];
} else if ( settings.hasOwnProperty( opt ) ) {
value = settings[ opt ];
} else if ( defaults.hasOwnProperty( opt ) ) {
value = defaults[ opt ];
} else {
return undefined;
}
// Check the boolean options, 'false' and 'no' should be treated as false.
// Copied from mediawiki.Util.js.
if ( opt === 'debug' ) {
if ( ( typeof value ) === 'string' &&
/^(no|false)$/i.test( value ) ) {
return false;
}
}
return value;
};
var // The maximum number of tries per article
maxTries = getOption( 'tries' ),
// The maximum number of fetch retries per article
maxFetchRetries = getOption( 'fetches' ),
// The time to wait before considering a test has failed
cutOffTime = getOption( 'cutofftime' ),
// The number of pages to fetch at once
batchSize = getOption( 'batch' ),
debug = getOption( 'debug' );
/**
* Does cassandra have to be shutdown on exit as well?
* process.on( 'exit', function() {
* db.end();
* } );
*/
var getTitle = function ( req, res ) {
res.end( 'get title not implemented yet');
};
var receiveResults = function ( req, res ) {
res.end( 'receive results not implemented yet' );
};
var statsWebInterface = function ( req, res ) {
res.write('<html><body>\n');
res.write('Stats web interface goes here');
res.end('</body></html>');
};
var failsWebInterface = function ( req, res ) {
res.write('<html><body>\n');
res.write('Fails page goes here');
res.end('</body></html>');
};
var resultsWebInterface = function ( req, res ) {
res.write('<html><body>\n');
res.write('Results page goes here');
res.end('</body></html>');
};
var resultWebInterface = function( req, res ) {
res.write('<html><body>\n');
res.write('Result diff page goes here');
res.end('</body></html>');
};
var GET_failedFetches = function( req, res ) {
res.write('<html><body>\n');
res.write('Failed fetches page go here');
res.end('</body></html>');
};
var GET_crashers = function( req, res ) {
res.write('<html><body>\n');
res.write('Crashed titles go here');
res.end('</body></html>');
};
var GET_failsDistr = function( req, res ) {
res.write('<html><body>\n');
res.write('Distribution of semantic errors go here');
res.end('</body></html>');
};
var GET_skipsDistr = function( req, res ) {
res.write('<html><body>\n');
res.write('Distribution of syntactic errors go here');
res.end('</body></html>');
};
var GET_regressions = function( req, res ) {
res.write('<html><body>\n');
res.write('Regressions page goes here');
res.end('</body></html>');
};
var GET_topfixes = function( req, res ) {
res.write('<html><body>\n');
res.write('Top fixes goes here');
res.end('</body></html>');
};
var GET_commits = function( req, res ) {
res.write('<html><body>\n');
res.write('Commits go here');
res.end('</body></html>');
};
var GET_perfStats = function( req, res ) {
res.write('<html><body>\n');
res.write('Performance stats go here');
res.end('</body></html>');
};
var GET_pagePerfStats = function( req, res ) {
res.write('<html><body>\n');
res.write('Performance results go here');
res.end('</body></html>');
};
// Make an app
var app = express.createServer();
// Configure for Handlebars
app.configure(function(){
app.set('view engine', 'handlebars');
app.register('.html', require('handlebars'));
});
// Declare static directory
app.use("/static", express.static(__dirname + "/static"));
// Make the coordinator app
var coordApp = express.createServer();
// Add in the bodyParser middleware (because it's pretty standard)
app.use( express.bodyParser() );
coordApp.use( express.bodyParser() );
// robots.txt: no indexing.
app.get(/^\/robots.txt$/, function ( req, res ) {
res.end( "User-agent: *\nDisallow: /\n" );
});
// Main interface
app.get( /^\/results(\/([^\/]+))?$/, resultsWebInterface );
// Results for a title (on latest commit)
app.get( /^\/latestresult\/([^\/]+)\/(.*)$/, resultWebInterface );
// Results for a title on any commit
app.get( /^\/result\/([a-f0-9]*)\/([^\/]+)\/(.*)$/, resultWebInterface );
// List of failures sorted by severity
app.get( /^\/topfails\/(\d+)$/, failsWebInterface );
// 0th page
app.get( /^\/topfails$/, failsWebInterface );
// Overview of stats
app.get( /^\/$/, statsWebInterface );
app.get( /^\/stats(\/([^\/]+))?$/, statsWebInterface );
// Failed fetches
app.get( /^\/failedFetches$/, GET_failedFetches );
// Crashers
app.get( /^\/crashers$/, GET_crashers );
// Regressions between two revisions.
app.get( /^\/regressions\/between\/([^\/]+)\/([^\/]+)(?:\/(\d+))?$/, GET_regressions );
// Topfixes between two revisions.
app.get( /^\/topfixes\/between\/([^\/]+)\/([^\/]+)(?:\/(\d+))?$/, GET_topfixes );
// Distribution of fails
app.get( /^\/failsDistr$/, GET_failsDistr );
// Distribution of fails
app.get( /^\/skipsDistr$/, GET_skipsDistr );
// Performance stats
app.get( /^\/perfstats\/(\d+)$/, GET_perfStats );
app.get( /^\/perfstats$/, GET_perfStats );
app.get( /^\/pageperfstats\/([^\/]+)\/(.*)$/, GET_pagePerfStats );
// List of all commits
app.use( '/commits', GET_commits );
app.use( '/static', express.static( __dirname + '/static' ) );
// Clients will GET this path if they want to run a test
coordApp.get( /^\/title$/, getTitle );
// Receive results from clients
coordApp.post( /^\/result\/([^\/]+)\/([^\/]+)/, receiveResults );
// Start the app
app.listen( 8001 );
coordApp.listen( 8002 );
}() );