Skip to content

Commit

Permalink
hackfix for unfortunate race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
perimosocordiae committed May 30, 2013
1 parent 0ab1375 commit b7d3d41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/node/test-fs-read-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var filepath = path.join(common.fixturesDir, 'x.txt'),
readCalled = 0,
rootFS = fs.getRootFS();

// Hack: process.exit is called when the last callback fires,
// so we wrap all this in a callback to avoid running
// the exit function after the open but before the read.
setImmediate(function(){
fs.open(filepath, 'r', function(err, fd) {
if (err) throw err;
fs.read(fd, bufferAsync, 0, expected.length, 0, function(err, bytesRead) {
Expand All @@ -43,6 +47,7 @@ fs.open(filepath, 'r', function(err, fd) {
assert.equal(r, expected.length);
}
});
});

process.on('exit', function() {
assert.equal(readCalled, 1);
Expand Down
5 changes: 5 additions & 0 deletions test/node/test-fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var filepath = path.join(common.fixturesDir, 'x.txt'),
readCalled = 0,
rootFS = fs.getRootFS();

// Hack: process.exit is called when the last callback fires,
// so we wrap all this in a callback to avoid running
// the exit function after the open but before the read.
setImmediate(function(){
fs.open(filepath, 'r', function(err, fd) {
if (err) throw err;

Expand All @@ -43,6 +47,7 @@ fs.open(filepath, 'r', function(err, fd) {
assert.equal(r[1], expected.length);
}
});
});

process.on('exit', function() {
assert.equal(readCalled, 1);
Expand Down

0 comments on commit b7d3d41

Please sign in to comment.