|
1 | | -var assert = require('assert'); |
2 | | -var Process = require('./support/process'); |
| 1 | +const assert = require('assert'); |
| 2 | +const Process = require('./support/process'); |
3 | 3 |
|
4 | | -var firstProcess = new Process('same-name'); |
5 | | -var secondProcess = new Process('same-name'); |
| 4 | +const firstProcess = new Process('same-name', 1); |
| 5 | +const secondProcess = new Process('same-name', 1); |
6 | 6 |
|
7 | 7 | describe('ProcessLock', function() { |
8 | | - it('firstProcess should be able to obtain lock', function(done) { |
9 | | - firstProcess.processLock.lock(function(){ |
10 | | - assert(firstProcess.processLock.owner); |
11 | | - done(); |
| 8 | + it('firstProcess should be able to obtain lock', function(done) { |
| 9 | + firstProcess.processLock.lock((err, result) => { |
| 10 | + assert.ifError(err); |
| 11 | + assert(firstProcess.processLock.owner); |
| 12 | + assert.equal(result, true); |
| 13 | + done(); |
| 14 | + }); |
12 | 15 | }); |
13 | | - }); |
14 | 16 |
|
15 | | - it('secondProcess should not be able to obtain the lock', function(done) { |
16 | | - secondProcess.processLock.lock(function() { |
17 | | - assert.equal(false, secondProcess.processLock.owner); |
18 | | - done(); |
| 17 | + it('secondProcess should not be able to obtain the lock', function(done) { |
| 18 | + secondProcess.processLock.lock((err, result) => { |
| 19 | + assert.ifError(err); |
| 20 | + assert.equal(result, false); |
| 21 | + assert.equal(false, secondProcess.processLock.owner); |
| 22 | + done(); |
| 23 | + }); |
19 | 24 | }); |
20 | | - }); |
21 | 25 |
|
22 | | - it('firstProcess should be able to let go of the lock', function(done) { |
23 | | - firstProcess.processLock.clear(function() { |
24 | | - assert.equal(false, firstProcess.processLock.owner); |
25 | | - done(); |
| 26 | + it('firstProcess should be able to let go of the lock', function(done) { |
| 27 | + firstProcess.processLock.clear((err, result) => { |
| 28 | + assert.ifError(err); |
| 29 | + assert.equal(result, true); |
| 30 | + assert.equal(false, firstProcess.processLock.owner); |
| 31 | + done(); |
| 32 | + }); |
26 | 33 | }); |
27 | | - }); |
28 | 34 |
|
29 | | - it('secondProcess should be able to obtain the lock', function(done) { |
30 | | - secondProcess.processLock.lock(function() { |
31 | | - assert.equal(true, secondProcess.processLock.owner); |
32 | | - done(); |
| 35 | + it('secondProcess should be able to obtain the lock', function(done) { |
| 36 | + secondProcess.processLock.lock((err, result) => { |
| 37 | + assert.ifError(err); |
| 38 | + assert.equal(secondProcess.processLock.timeout, 1); |
| 39 | + assert.equal(result, true); |
| 40 | + assert.equal(true, secondProcess.processLock.owner); |
| 41 | + done(); |
| 42 | + }); |
33 | 43 | }); |
34 | | - }); |
35 | 44 |
|
36 | | - it('secondProcess should be able to update the lock', function(done) { |
37 | | - this.timeout(7000); |
38 | | - |
39 | | - setTimeout(function() { |
40 | | - secondProcess.processLock.update(function() { |
41 | | - assert(secondProcess.processLock.owner); |
42 | | - done(); |
43 | | - }); |
44 | | - }, 5000) |
45 | | - }); |
46 | | - |
47 | | - it('firstProcess should not be able to update the lock', function(done) { |
48 | | - this.timeout(5000); |
49 | | - |
50 | | - setTimeout(function() { |
51 | | - firstProcess.processLock.update(function() { |
52 | | - assert.equal(false, firstProcess.processLock.owner); |
53 | | - done(); |
54 | | - }); |
55 | | - }, 2000); |
56 | | - }); |
57 | | - |
58 | | - it('firstProcess should not be able to lock because secondProcess recently updated', function(done) { |
59 | | - this.timeout(15000); |
| 45 | + it('secondProcess should be able to update the lock', function(done) { |
| 46 | + setTimeout(() => { |
| 47 | + secondProcess.processLock.update((err, result) => { |
| 48 | + assert.ifError(err); |
| 49 | + assert.equal(result, true); |
| 50 | + assert(secondProcess.processLock.owner); |
| 51 | + done(); |
| 52 | + }); |
| 53 | + }, 500) |
| 54 | + }); |
60 | 55 |
|
61 | | - setTimeout(function() { |
62 | | - firstProcess.processLock.lock(function() { |
63 | | - assert.equal(false, firstProcess.processLock.owner); |
64 | | - done(); |
65 | | - }); |
66 | | - }, 7000); |
67 | | - }); |
| 56 | + it('firstProcess should not be able to update the lock', function(done) { |
| 57 | + setTimeout(() => { |
| 58 | + firstProcess.processLock.update((err, result) => { |
| 59 | + assert.ifError(err); |
| 60 | + assert.equal(result, false); |
| 61 | + assert.equal(false, firstProcess.processLock.owner); |
| 62 | + done(); |
| 63 | + }); |
| 64 | + }, 500); |
| 65 | + }); |
68 | 66 |
|
69 | | - it('firstProcess should be able to lock due to timeout', function(done) { |
70 | | - this.timeout(12000) |
| 67 | + it('firstProcess should not be able to lock because secondProcess recently updated', function(done) { |
| 68 | + setTimeout(() => { |
| 69 | + firstProcess.processLock.lock((err, result) => { |
| 70 | + assert.ifError(err); |
| 71 | + assert.equal(result, false); |
| 72 | + assert.equal(false, firstProcess.processLock.owner); |
| 73 | + done(); |
| 74 | + }); |
| 75 | + }, 250); |
| 76 | + }); |
71 | 77 |
|
72 | | - setTimeout(function() { |
73 | | - firstProcess.processLock.lock(function() { |
74 | | - assert(firstProcess.processLock.owner); |
75 | | - done(); |
76 | | - }); |
77 | | - }, 10000) |
78 | | - }) |
| 78 | + it('firstProcess should be able to lock due to timeout', function(done) { |
| 79 | + setTimeout(() => { |
| 80 | + firstProcess.processLock.lock((err, result) => { |
| 81 | + assert.ifError(err); |
| 82 | + assert.equal(result, true); |
| 83 | + assert(firstProcess.processLock.owner); |
| 84 | + done(); |
| 85 | + }); |
| 86 | + }, 1500) |
| 87 | + }); |
79 | 88 |
|
80 | | - it('secondProcess should be able to force the lock to clear', function(done) { |
81 | | - secondProcess.processLock.clear(function(){ |
82 | | - secondProcess.processLock.state(function(state) { |
83 | | - assert.equal('open', state); |
84 | | - done(); |
85 | | - }) |
86 | | - }, true) |
87 | | - }) |
| 89 | + it('secondProcess should be able to force the lock to clear', function(done) { |
| 90 | + secondProcess.processLock.clear(true, (err, result) => { |
| 91 | + assert.ifError(err); |
| 92 | + assert.equal(result, true); |
| 93 | + secondProcess.processLock.state((err, state) => { |
| 94 | + assert.ifError(err); |
| 95 | + assert.equal('open', state); |
| 96 | + done(); |
| 97 | + }) |
| 98 | + }); |
| 99 | + }); |
88 | 100 |
|
| 101 | + it('second lock clear returns null', (done) => { |
| 102 | + secondProcess.processLock.clear(true, (err, result) => { |
| 103 | + assert.ifError(err); |
| 104 | + assert.equal(result, null); |
| 105 | + done(); |
| 106 | + }); |
| 107 | + }); |
89 | 108 | }); |
0 commit comments