Skip to content

Commit 3caa77c

Browse files
committed
add additional unit tests
1 parent 5dab987 commit 3caa77c

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

test/cli.mocha.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function execCLI(args, options) {
2222
return childProcess.spawn(process.execPath, fullArgs, options);
2323
}
2424

25-
const FAST_OPTS = '-t 1s -i 100 -w 100'.split(' ');
25+
26+
const FAST_OPTS = '-t 1000 -i 100 -w 100'.split(' ');
27+
const FAST_OPTS_TIMEOUT_UNIT = '-t 1s -i 100 -w 100'.split(' ');
28+
2629

2730
describe('cli', function () {
2831
this.timeout(3000);
@@ -271,6 +274,22 @@ describe('cli', function () {
271274
});
272275
});
273276

277+
it('should timeout when all resources are not available and timout option is specified with unit', function (done) {
278+
temp.mkdir({}, function (err, dirPath) {
279+
if (err) return done(err);
280+
const opts = {
281+
resources: [path.resolve(dirPath, 'foo')],
282+
timeout: '1s'
283+
};
284+
// timeout is in FAST_OPTS
285+
execCLI(opts.resources.concat(FAST_OPTS_TIMEOUT_UNIT), {}).on('exit', function (code) {
286+
expect(code).toNotBe(0);
287+
done();
288+
});
289+
});
290+
});
291+
292+
274293
it('should timeout when some resources are not available and timout option is specified', function (done) {
275294
temp.mkdir({}, function (err, dirPath) {
276295
if (err) return done(err);
@@ -349,6 +368,31 @@ describe('cli', function () {
349368
});
350369
});
351370

371+
it('should timeout when an http resource does not respond before httpTimeout specified with unit', function (done) {
372+
const opts = {
373+
resources: ['http://localhost:8125'],
374+
timeout: 1000,
375+
interval: 100,
376+
window: 100,
377+
httpTimeout: '70ms'
378+
};
379+
380+
httpServer = http.createServer().on('request', function (req, res) {
381+
// make it a slow response, longer than the httpTimeout
382+
setTimeout(function () {
383+
res.end('data');
384+
}, 90);
385+
});
386+
httpServer.listen(8125, 'localhost');
387+
388+
const addOpts = '--httpTimeout 70ms'.split(' ');
389+
// timeout, interval, and window are in FAST_OPTS
390+
execCLI(opts.resources.concat(FAST_OPTS).concat(addOpts), {}).on('exit', function (code) {
391+
expect(code).toNotBe(0);
392+
done();
393+
});
394+
});
395+
352396
it('should timeout when an http GET resource is not available', function (done) {
353397
const opts = {
354398
resources: ['http-get://localhost:3999'],
@@ -422,6 +466,21 @@ describe('cli', function () {
422466
});
423467
});
424468

469+
it('should timeout when a service host is unreachable, tcpTimeout specified with unit', function (done) {
470+
const opts = {
471+
resources: ['tcp:256.0.0.1:1234'],
472+
timeout: 1000,
473+
tcpTimeout: '1s'
474+
};
475+
476+
const addOpts = '--tcpTimeout 1s'.split(' ');
477+
// timeout is in FAST_OPTS
478+
execCLI(opts.resources.concat(FAST_OPTS).concat(addOpts), {}).on('exit', function (code) {
479+
expect(code).toNotBe(0);
480+
done();
481+
});
482+
});
483+
425484
it('should timeout when a service is not listening to a socket', function (done) {
426485
let socketPath;
427486
temp.mkdir({}, function (err, dirPath) {

0 commit comments

Comments
 (0)