Skip to content

Commit

Permalink
Merge pull request #3760 from seaoak/bugfix/test-of-box-fails-on-race…
Browse files Browse the repository at this point in the history
…-condition

test: Fix up potential race condition in test cases of "box" (fix #3759)
  • Loading branch information
curbengh committed Oct 12, 2019
2 parents e61116a + e353f46 commit bd70086
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions test/scripts/box/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('Box', () => {
}).finally(() => fs.rmdir(box.base));
});

it('process() - mtime changed', () => {
it('process() - update (mtime changed and hash changed)', () => {
const box = newBox('test');
const name = 'a.txt';
const path = pathFn.join(box.base, name);
Expand All @@ -139,7 +139,8 @@ describe('Box', () => {
fs.writeFile(path, 'a'),
box.Cache.insert({
_id: cacheId,
modified: 0
modified: 0,
hash: util.hash('b').toString('hex')
})
]).then(() => box.process()).then(() => {
const file = processor.args[0][0];
Expand All @@ -148,7 +149,7 @@ describe('Box', () => {
}).finally(() => fs.rmdir(box.base));
});

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

return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({
_id: cacheId
_id: cacheId,
modified: 0,
hash: util.hash('a').toString('hex')
})).then(() => box.process()).then(() => {
const file = processor.args[0][0];
file.type.should.eql('update');
file.type.should.eql('skip');
file.path.should.eql(name);
}).finally(() => fs.rmdir(box.base));

});

it('process() - skip (hash changed but mtime matched)', () => {
const box = newBox('test');
const name = 'a.txt';
const path = pathFn.join(box.base, name);
const cacheId = 'test/' + name;

const processor = sinon.spy();
box.addProcessor(processor);

return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({
_id: cacheId,
modified: stats.mtime,
hash: util.hash('b').toString('hex')
})).then(() => box.process()).then(() => {
const file = processor.args[0][0];
file.type.should.eql('skip');
file.path.should.eql(name);
}).finally(() => fs.rmdir(box.base));
});

it('process() - skip', () => {
it('process() - skip (mtime matched and hash matched)', () => {
const box = newBox('test');
const name = 'a.txt';
const path = pathFn.join(box.base, name);
Expand Down

0 comments on commit bd70086

Please sign in to comment.