Skip to content

Commit b6d426a

Browse files
committed
fixin: adding predicate checks to converted tests
1 parent 8f4af04 commit b6d426a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/EncryptedFS.concurrent.test.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,29 +307,35 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
307307
});
308308
describe('concurrent file writes', () => {
309309
test('EncryptedFS.write on multiple file descriptors', async () => {
310-
const contents = ['one', 'two'];
310+
// Concurrent writes of different length results in "last write wins" or a merge
311+
const contents = ['one', 'two', 'one1', 'two2'];
311312
await fc.assert(
312313
fc.asyncProperty(fc.scheduler(), async (s) => {
313314
const fds: Array<FdIndex> = [
314315
await efs.open('test', constants.O_RDWR | constants.O_CREAT),
315316
await efs.open('test', constants.O_RDWR | constants.O_CREAT),
317+
await efs.open('test', constants.O_RDWR | constants.O_CREAT),
318+
await efs.open('test', constants.O_RDWR | constants.O_CREAT),
316319
];
317320

321+
// Concurrent writes of the same length results in "last write wins"
318322
const prom = Promise.all([
319323
scheduleCall(s, () => efs.write(fds[0], contents[0]), 'write 1'),
320324
scheduleCall(s, () => efs.write(fds[1], contents[1]), 'write 2'),
325+
scheduleCall(s, () => efs.write(fds[2], contents[2]), 'write 3'),
326+
scheduleCall(s, () => efs.write(fds[3], contents[3]), 'write 4'),
321327
]);
322328
await s.waitAll();
323329
await prom;
324330

325-
expect(
331+
expect(['one', 'two', 'one1', 'one2', 'two2', 'two1']).toContainEqual(
326332
await efs.readFile('test', { encoding: 'utf-8' }),
327-
).toHaveLength(3);
333+
);
328334
for (const fd of fds) {
329335
await efs.close(fd);
330336
}
331337
}),
332-
{ numRuns: 20, interruptAfterTimeLimit },
338+
{ numRuns: 50, interruptAfterTimeLimit },
333339
);
334340
});
335341
test('EncryptedFS.write on the same file descriptor', async () => {
@@ -345,9 +351,9 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
345351
await s.waitAll();
346352
await prom;
347353

348-
expect(
354+
expect(['aaabbb', 'bbbaaa']).toContainEqual(
349355
await efs.readFile('test', { encoding: 'utf-8' }),
350-
).toHaveLength(6);
356+
);
351357
await efs.close(fd);
352358
}),
353359
{ numRuns: 20, interruptAfterTimeLimit },
@@ -356,26 +362,30 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
356362
test('EncryptedFS.writeFile', async () => {
357363
await fc.assert(
358364
fc.asyncProperty(fc.scheduler(), async (s) => {
365+
// Concurrent writes of different length results in "last write wins" or a merge
359366
await efs.writeFile('test', '');
360367

361368
const prom = Promise.all([
362369
scheduleCall(s, () => efs.writeFile('test', 'one'), 'writeFile 1'),
370+
scheduleCall(s, () => efs.writeFile('test', 'one1'), 'writeFile 2'),
371+
scheduleCall(s, () => efs.writeFile('test', 'two'), 'writeFile 2'),
363372
scheduleCall(s, () => efs.writeFile('test', 'two2'), 'writeFile 2'),
364373
]);
365374
await s.waitAll();
366375
await prom;
367376

368-
expect(
377+
expect(['one', 'two', 'one1', 'one2', 'two2', 'two1']).toContainEqual(
369378
await efs.readFile('test', { encoding: 'utf-8' }),
370-
).toHaveLength(4);
379+
);
371380
expect(await totalINodes(iNodeMgr)).toEqual(2);
372381
}),
373-
{ numRuns: 20, interruptAfterTimeLimit },
382+
{ numRuns: 50, interruptAfterTimeLimit },
374383
);
375384
});
376385
test('EncryptedFS.appendFile', async () => {
377386
await fc.assert(
378387
fc.asyncProperty(fc.scheduler(), async (s) => {
388+
// Concurrent appends results in mutually exclusive writes
379389
await efs.writeFile('test', 'original');
380390

381391
const prom = Promise.all([

0 commit comments

Comments
 (0)