-
Notifications
You must be signed in to change notification settings - Fork 21
/
test.js
55 lines (47 loc) · 1.44 KB
/
test.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
var http = require('http');
var httpShutdown = require('./index').extend();
var should = require('chai').should();
var request = require('request');
describe('http-shutdown', function(done) {
it('Should shutdown with no traffic', function(done) {
var server = http.createServer(function(req, res) {
done.fail();
}).withShutdown();
server.listen(16789, function() {
server.shutdown(function(err) {
should.not.exist(err);
done();
})
})
});
it('Should shutdown with outstanding traffic', function(done) {
var server = http.createServer(function(req, res) {
setTimeout(function() {
res.writeHead(200);
res.end('All done');
}, 500);
}).withShutdown();
server.listen(16789, function(err) {
request.get('http://localhost:16789/', function(err, response) {
should.not.exist(err);
response.statusCode.should.equal(200);
done();
});
setTimeout(server.shutdown, 100);
});
});
it('Should force shutdown without waiting for outstanding traffic', function(done) {
var server = http.createServer(function(req, res) {
setTimeout(function() {
done.fail();
}, 500);
}).withShutdown();
server.listen(16789, function(err) {
request.get('http://localhost:16789/', function(err, response) {
should.exist(err);
done();
});
setTimeout(server.forceShutdown, 100);
});
});
});