Skip to content

Commit bd70086

Browse files
authored
Merge pull request #3760 from seaoak/bugfix/test-of-box-fails-on-race-condition
test: Fix up potential race condition in test cases of "box" (fix #3759)
2 parents e61116a + e353f46 commit bd70086

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

test/scripts/box/box.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('Box', () => {
126126
}).finally(() => fs.rmdir(box.base));
127127
});
128128

129-
it('process() - mtime changed', () => {
129+
it('process() - update (mtime changed and hash changed)', () => {
130130
const box = newBox('test');
131131
const name = 'a.txt';
132132
const path = pathFn.join(box.base, name);
@@ -139,7 +139,8 @@ describe('Box', () => {
139139
fs.writeFile(path, 'a'),
140140
box.Cache.insert({
141141
_id: cacheId,
142-
modified: 0
142+
modified: 0,
143+
hash: util.hash('b').toString('hex')
143144
})
144145
]).then(() => box.process()).then(() => {
145146
const file = processor.args[0][0];
@@ -148,7 +149,7 @@ describe('Box', () => {
148149
}).finally(() => fs.rmdir(box.base));
149150
});
150151

151-
it('process() - hash changed', () => {
152+
it('process() - skip (mtime changed but hash matched)', () => {
152153
const box = newBox('test');
153154
const name = 'a.txt';
154155
const path = pathFn.join(box.base, name);
@@ -158,15 +159,38 @@ describe('Box', () => {
158159
box.addProcessor(processor);
159160

160161
return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({
161-
_id: cacheId
162+
_id: cacheId,
163+
modified: 0,
164+
hash: util.hash('a').toString('hex')
162165
})).then(() => box.process()).then(() => {
163166
const file = processor.args[0][0];
164-
file.type.should.eql('update');
167+
file.type.should.eql('skip');
168+
file.path.should.eql(name);
169+
}).finally(() => fs.rmdir(box.base));
170+
171+
});
172+
173+
it('process() - skip (hash changed but mtime matched)', () => {
174+
const box = newBox('test');
175+
const name = 'a.txt';
176+
const path = pathFn.join(box.base, name);
177+
const cacheId = 'test/' + name;
178+
179+
const processor = sinon.spy();
180+
box.addProcessor(processor);
181+
182+
return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({
183+
_id: cacheId,
184+
modified: stats.mtime,
185+
hash: util.hash('b').toString('hex')
186+
})).then(() => box.process()).then(() => {
187+
const file = processor.args[0][0];
188+
file.type.should.eql('skip');
165189
file.path.should.eql(name);
166190
}).finally(() => fs.rmdir(box.base));
167191
});
168192

169-
it('process() - skip', () => {
193+
it('process() - skip (mtime matched and hash matched)', () => {
170194
const box = newBox('test');
171195
const name = 'a.txt';
172196
const path = pathFn.join(box.base, name);

0 commit comments

Comments
 (0)