From caf8dc84dac8bfaee51164d34afa9ccc5a604a0d Mon Sep 17 00:00:00 2001 From: Harry Lachenmayer Date: Tue, 17 Jul 2018 17:31:19 +0100 Subject: [PATCH] add simultaneous read/write test --- index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/index.js b/index.js index 1190867..850ef86 100644 --- a/index.js +++ b/index.js @@ -267,4 +267,43 @@ module.exports = function(createRandomAccessFile, options) { ) }) } + + tape("simultaneous writes and reads", function(t) { + let i = 0 + createRandomAccessFile("write-and-read-simultaneous.txt", null, function(file) { + file.write(0, Buffer.from("hello"), function(err) { + t.error(err, "no error") + file.read(0, 5, function(err, buf) { + t.error(err, "no error") + t.same(buf, Buffer.from("hello")) + i++ + if (i == 3) { + file.destroy(t.end) + } + }) + }) + file.write(10, Buffer.from("hallo"), function(err) { + t.error(err, "no error") + file.read(10, 5, function(err, buf) { + t.error(err, "no error") + t.same(buf, Buffer.from("hallo")) + i++ + if (i == 3) { + file.destroy(t.end) + } + }) + }) + file.write(5, Buffer.from("hola!"), function(err) { + t.error(err, "no error") + file.read(5, 5, function(err, buf) { + t.error(err, "no error") + t.same(buf, Buffer.from("hola!")) + i++ + if (i == 3) { + file.destroy(t.end) + } + }) + }) + }) + }) }