/
run.js
483 lines (420 loc) · 13.3 KB
/
run.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
var selftest = require('../tool-testing/selftest.js');
var Sandbox = selftest.Sandbox;
var utils = require('../utils/utils.js');
var net = require('net');
var Future = require('fibers/future');
var _ = require('underscore');
var files = require('../fs/files.js');
var catalog = require('../packaging/catalog/catalog.js');
var DEFAULT_RELEASE_TRACK = catalog.DEFAULT_TRACK;
var MONGO_LISTENING =
{ stdout: " [initandlisten] waiting for connections on port" };
var SIMPLE_WAREHOUSE = {
v1: { },
v2: { recommended: true },
v3: { }
};
selftest.define("run", function () {
var s = new Sandbox({ fakeMongo: true });
var run;
// Starting a run
s.createApp("myapp", "standard-app");
s.cd("myapp");
s.set("METEOR_TEST_TMP", files.convertToOSPath(files.mkdtemp()));
run = s.run();
run.match("myapp");
run.match("proxy");
run.tellMongo(MONGO_LISTENING);
run.match("MongoDB");
run.match("your app");
run.waitSecs(5);
run.match("running at");
run.match("localhost");
// File change
s.write("empty.js", "");
run.waitSecs(2);
run.match("restarted");
s.write("empty.js", " ");
run.waitSecs(2);
run.match("restarted");
// XXX want app to generate output so that we can see restart counter reset
// Crashes
s.write("crash.js", "process.exit(42);");
run.waitSecs(5);
run.match("with code: 42");
run.waitSecs(5);
run.match("is crashing");
s.unlink("crash.js");
run.waitSecs(5);
run.match("Modified");
run.waitSecs(5);
run.match("restarted");
s.write("empty.js", "");
run.waitSecs(5);
// We used to see the restart counter reset but right now restart messages
// don't coalesce due to intermediate use of the progress bar.
run.match("restarted");
s.write("crash.js", "process.kill(process.pid, 'SIGKILL');");
run.waitSecs(5);
run.match("Exited");
run.match("is crashing");
// Bundle failure
s.unlink("crash.js");
s.write("junk.css", "/*");
run.waitSecs(5);
run.match("Modified");
run.match("prevented startup");
run.match("End of comment missing");
run.match("file change");
// Back to working
s.unlink("junk.css");
run.waitSecs(5);
run.match("restarted");
// Crash just once, then restart successfully
s.write("crash.js", `
var fs = Npm.require('fs');
var path = Npm.require('path');
var crashmark = path.join(process.env.METEOR_TEST_TMP, 'crashed');
try {
fs.readFileSync(crashmark);
} catch (e) {
fs.writeFileSync(crashmark);
process.exit(137);
}`);
run.waitSecs(5);
run.match("with code: 137");
run.waitSecs(5);
run.match("restarted");
run.stop();
s.unlink("crash.js");
run = s.run('--settings', 's.json');
run.waitSecs(5);
run.match('s.json: file not found (settings file)');
run.match('Waiting for file change');
s.write('s.json', '}');
run.match('s.json: parse error reading settings file');
run.match('Waiting for file change');
s.write('s.json', '{}');
run.waitSecs(15);
run.match('App running at');
run.stop();
// How about a bundle failure right at startup
s.write("junk.css", "/*");
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("prevented startup");
run.match("End of comment missing");
run.match("file change");
s.unlink("junk.css");
run.waitSecs(5);
run.match("restarted");
run.stop();
// XXX --port, --production, --raw-logs, --settings, --program
});
selftest.define("run --once", ["yet-unsolved-windows-failure"], function () {
var s = new Sandbox({ fakeMongo: true });
var run;
s.createApp("onceapp", "once");
s.cd("onceapp");
// Basic run --once
s.set("RUN_ONCE_OUTCOME", "exit");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("once test\n");
run.expectExit(123);
// run --once, exit on signal
s.set("RUN_ONCE_OUTCOME", "kill");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("once test\n");
run.matchErr("Killed (SIGKILL)\n");
run.expectExit(255);
// run --once, bundle failure
s.set("RUN_ONCE_OUTCOME", "exit");
s.write("junk.css", "/*");
run = s.run("--once");
run.waitSecs(5);
run.matchErr("Build failed");
run.matchErr("End of comment missing");
run.expectExit(254);
s.unlink("junk.css");
// file changes don't make it restart
s.set("RUN_ONCE_OUTCOME", "hang");
run = s.run("--once");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(5);
run.match("once test\n");
s.write('empty.js', 'null');
var originalRelease = s.read('.meteor/release');
s.write('.meteor/release', 'v1');
utils.sleepMs(2000); // sorry, hard to avoid
run.stop();
run.forbidAll("updated");
s.unlink('empty.js');
s.write('.meteor/release', originalRelease);
// Try it with a real Mongo. Make sure that it actually starts one.
s = new Sandbox;
s.createApp("onceapp", "once");
s.cd("onceapp");
s.set("RUN_ONCE_OUTCOME", "mongo");
run = s.run("--once");
run.waitSecs(30);
run.expectExit(86);
});
selftest.define("run errors", function () {
var s = new Sandbox;
s.createApp("myapp", "standard-app");
s.cd("myapp");
// Prevent mongod from starting up. (Note that "127.0.0.1" matches the
// interface that mongo uses.)
var proxyPort = utils.randomPort();
var mongoPort = proxyPort + 1;
var f = new Future;
var server = net.createServer().listen(mongoPort, "127.0.0.1", f.resolver());
f.wait();
var run = s.run("-p", proxyPort);
_.times(2, function () {
run.waitSecs(30);
run.match("Unexpected mongo exit code 48. Restarting.");
});
run.waitSecs(3);
run.match("Can't start Mongo server");
run.match("MongoDB exited because its port was closed");
run.match("running in the same project.\n");
run.expectEnd();
run.forbid("Started MongoDB");
run.expectExit(254);
f = new Future;
server.close(f.resolver());
f.wait();
// This time, prevent the proxy from starting. (This time, leaving out the
// interface name matches.)
f = new Future;
server = net.createServer().listen(proxyPort, f.resolver());
f.wait();
run = s.run("-p", proxyPort);
run.waitSecs(3);
run.match(/Can't listen on port.*another Meteor/);
run.expectExit(254);
f = new Future;
server.close(f.resolver());
f.wait();
});
selftest.define("update during run", ["checkout", 'custom-warehouse'], function () {
var s = new Sandbox({
warehouse: SIMPLE_WAREHOUSE,
fakeMongo: true
});
var run;
s.createApp("myapp", "packageless", { release: DEFAULT_RELEASE_TRACK + '@v1' });
s.cd("myapp");
// If the app version changes, we exit with an error message.
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(10);
run.match('localhost:3000');
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v2');
run.matchErr('to Meteor v2 from Meteor v1');
run.expectExit(254);
// But not if the release was forced (case 1)
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v1');
run = s.run("--release", DEFAULT_RELEASE_TRACK + "@v3");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2);
run.match('localhost:3000');
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v2');
s.write('empty.js', '');
run.waitSecs(2);
run.match('restarted');
run.stop();
run.forbidAll("updated");
// But not if the release was forced (case 2)
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v1');
run = s.run("--release", DEFAULT_RELEASE_TRACK + "@v1");
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2);
run.match('localhost:3000');
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v2');
s.write('empty.js', '');
run.waitSecs(2);
run.match('restarted');
run.stop();
run.forbidAll("updated");
// Nor do we do it if you're running from a checkout
s = new Sandbox({ fakeMongo: true });
s.createApp("myapp", "standard-app");
s.cd("myapp");
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v1');
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2);
run.match('localhost:3000');
s.write('.meteor/release', DEFAULT_RELEASE_TRACK + '@v2');
s.write('empty.js', '');
run.waitSecs(2);
run.match('restarted');
run.stop();
run.forbidAll("updated");
});
selftest.define("run with mongo crash", ["checkout"], function () {
var s = new Sandbox({ fakeMongo: true });
var run;
s.createApp("myapp", "standard-app");
s.cd("myapp");
// Kill mongod three times. See that it gives up and quits.
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2);
run.match('localhost:3000/\n');
if (process.platform === "win32") {
run.match('Type Control-C twice to stop.\n\n');
}
run.tellMongo({exit: 23});
run.read('Unexpected mongo exit code 23. Restarting.\n');
run.tellMongo({exit: 46});
run.read('Unexpected mongo exit code 46. Restarting.\n');
run.tellMongo({exit: 47});
run.read('Unexpected mongo exit code 47. Restarting.\n');
run.read("Can't start Mongo server.\n");
run.read("MongoDB exited due to excess clock skew\n");
run.expectEnd();
run.expectExit(254);
// Now create a build failure. Make sure that killing mongod three times
// *also* successfully quits even if we're waiting on file change.
s.write('bad.css', '/*');
run = s.run();
run.tellMongo(MONGO_LISTENING);
run.waitSecs(2);
run.match("prevented startup");
run.match("file change.\n");
run.tellMongo({exit: 23});
run.match('Unexpected mongo exit code 23. Restarting.\n');
run.tellMongo({exit: 46});
run.read('Unexpected mongo exit code 46. Restarting.\n');
run.tellMongo({exit: 47});
run.read('Unexpected mongo exit code 47. Restarting.\n');
run.read("Can't start Mongo server.\n");
run.read("MongoDB exited due to excess clock skew\n");
run.expectEnd();
run.expectExit(254);
});
// Test that when the parent runner process is SIGKILLed, the child
// process exits also.
selftest.define("run and SIGKILL parent process", ["yet-unsolved-windows-failure"], function () {
var s = new Sandbox();
var run;
s.createApp("myapp", "app-prints-pid");
s.cd("myapp");
run = s.run();
run.waitSecs(30);
var match = run.match(/My pid is (\d+)/);
var childPid;
if (! match || ! match[1]) {
selftest.fail("No pid printed");
}
childPid = match[1];
process.kill(run.proc.pid, "SIGKILL");
// This sleep should be a little more time than the interval at which
// the child checks if the parent is still alive, in
// packages/webapp/webapp_server.js.
utils.sleepMs(3500);
// Send the child process a signal of 0. If there is no error, it
// means that the process is still running, which is not what we
// expect.
var caughtError;
try {
process.kill(childPid, 0);
} catch (err) {
caughtError = err;
}
if (! caughtError) {
selftest.fail("Child process " + childPid + " is still running");
}
run.stop();
// Test that passing a bad pid in $METEOR_PARENT_PID logs an error and exits
// immediately.
s.set("METEOR_BAD_PARENT_PID_FOR_TEST", "t");
run = s.run();
run.waitSecs(120);
run.match("must be a valid process ID");
run.match("Your application is crashing");
run.stop();
});
selftest.define("'meteor run --port' accepts/rejects proper values", function () {
var s = new Sandbox();
var run;
s.createApp("myapp", "standard-app");
s.cd("myapp");
run = s.run("run", "--port", "example.com");
run.waitSecs(30);
run.matchErr("--port must include a port");
run.expectExit(1);
run = s.run("run", "--port", "http://example.com");
run.waitSecs(30);
run.matchErr("--port must include a port");
run.expectExit(1);
run = s.run("run", "--port", "3500");
run.waitSecs(30);
run.match('App running at: http://localhost:3500/');
run.stop();
run = s.run("run", "--port", "127.0.0.1:3500");
run.waitSecs(30);
run.match('App running at: http://127.0.0.1:3500/');
run.stop();
});
// Regression test for #3582. Previously, meteor run would ignore changes to
// .meteor/versions that originate outside of the process.
selftest.define("update package during run", function () {
var s = new Sandbox();
s.createApp("myapp", "app-with-atmosphere-package");
s.cd("myapp", function () {
// The app starts with this package at 0.0.1 (based on its
// .meteor/versions). 0.0.2 exists too. (These are on the real atmosphere
// server.)
var listRun = s.run("list");
listRun.waitSecs(3);
listRun.match(/glasser:package-for-selftest.*0.0.1\*/);
listRun.match(/\* New versions/);
listRun.expectExit(0);
var runRun = s.run();
runRun.waitSecs(3);
runRun.match("App running at:");
var updateRun = s.run("update", "glasser:package-for-selftest");
updateRun.match(
/glasser:package-for-selftest.*upgraded from 0.0.1 to 0.0.2/);
updateRun.expectExit(0);
runRun.match("restarted");
listRun = s.run("list");
// When #3582 existed, the `meteor run` would revert this back to 0.0.1
// before it restarted.
listRun.match(/glasser:package-for-selftest.*0.0.2 /);
listRun.expectExit(0);
runRun.stop();
});
});
selftest.define("run logging in order", function () {
var s = new Sandbox({ fakeMongo: true });
var run;
// Starting a run
s.createApp("myapp", "standard-app");
s.cd("myapp");
s.write('packageless.js', `
Meteor.startup(function() {
for (var i = 0; i < 100000; i++) {
console.log('line: ' + i + '.');
}
});
`);
run = s.run();
run.match("myapp");
run.match("proxy");
run.tellMongo(MONGO_LISTENING);
run.match("MongoDB");
run.waitSecs(5);
for (var i = 0; i < 100000; i++) {
run.match(`line: ${i}.`);
}
});