forked from breser/git2consul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git2consul_graceful_shutdown_test.js
49 lines (36 loc) · 1.39 KB
/
git2consul_graceful_shutdown_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
var should = require('should');
// We want this above any git2consul module to make sure logging gets configured
var bootstrap = require('./git2consul_bootstrap_test.js');
var git = require('../lib/git');
var git_utils = require('./utils/git_utils.js');
describe('Graceful Shutdown', function() {
it ('should successfully fire if nothing else is happening', function(done) {
git.gracefulShutdown(function() {
done();
});
});
it ('should successfully fire if other stuff is happening', function(done) {
git_utils.initRepo(function(err, repo) {
if (err) return done(err);
// This should be set only once the handle ref has completed.
var shutdown_seen = false;
var sample_key = 'sample_key';
var sample_value = 'new test data';
git_utils.addFileToGitRepo(sample_key, sample_value, "Update a file.", function(err) {
if (err) return done(err);
var ref_change_handled = false;
repo.branches['master'].handleRefChange(0, function(err) {
if (err) return done(err);
shutdown_seen.should.equal(false);
ref_change_handled = true;
});
// This should not fire until after we've processed the handleRefChange above
git.gracefulShutdown(function() {
shutdown_seen = true;
ref_change_handled.should.equal(true);
done();
});
});
});
});
});