@@ -307,29 +307,35 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
307
307
} ) ;
308
308
describe ( 'concurrent file writes' , ( ) => {
309
309
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' ] ;
311
312
await fc . assert (
312
313
fc . asyncProperty ( fc . scheduler ( ) , async ( s ) => {
313
314
const fds : Array < FdIndex > = [
314
315
await efs . open ( 'test' , constants . O_RDWR | constants . O_CREAT ) ,
315
316
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 ) ,
316
319
] ;
317
320
321
+ // Concurrent writes of the same length results in "last write wins"
318
322
const prom = Promise . all ( [
319
323
scheduleCall ( s , ( ) => efs . write ( fds [ 0 ] , contents [ 0 ] ) , 'write 1' ) ,
320
324
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' ) ,
321
327
] ) ;
322
328
await s . waitAll ( ) ;
323
329
await prom ;
324
330
325
- expect (
331
+ expect ( [ 'one' , 'two' , 'one1' , 'one2' , 'two2' , 'two1' ] ) . toContainEqual (
326
332
await efs . readFile ( 'test' , { encoding : 'utf-8' } ) ,
327
- ) . toHaveLength ( 3 ) ;
333
+ ) ;
328
334
for ( const fd of fds ) {
329
335
await efs . close ( fd ) ;
330
336
}
331
337
} ) ,
332
- { numRuns : 20 , interruptAfterTimeLimit } ,
338
+ { numRuns : 50 , interruptAfterTimeLimit } ,
333
339
) ;
334
340
} ) ;
335
341
test ( 'EncryptedFS.write on the same file descriptor' , async ( ) => {
@@ -345,9 +351,9 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
345
351
await s . waitAll ( ) ;
346
352
await prom ;
347
353
348
- expect (
354
+ expect ( [ 'aaabbb' , 'bbbaaa' ] ) . toContainEqual (
349
355
await efs . readFile ( 'test' , { encoding : 'utf-8' } ) ,
350
- ) . toHaveLength ( 6 ) ;
356
+ ) ;
351
357
await efs . close ( fd ) ;
352
358
} ) ,
353
359
{ numRuns : 20 , interruptAfterTimeLimit } ,
@@ -356,26 +362,30 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
356
362
test ( 'EncryptedFS.writeFile' , async ( ) => {
357
363
await fc . assert (
358
364
fc . asyncProperty ( fc . scheduler ( ) , async ( s ) => {
365
+ // Concurrent writes of different length results in "last write wins" or a merge
359
366
await efs . writeFile ( 'test' , '' ) ;
360
367
361
368
const prom = Promise . all ( [
362
369
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' ) ,
363
372
scheduleCall ( s , ( ) => efs . writeFile ( 'test' , 'two2' ) , 'writeFile 2' ) ,
364
373
] ) ;
365
374
await s . waitAll ( ) ;
366
375
await prom ;
367
376
368
- expect (
377
+ expect ( [ 'one' , 'two' , 'one1' , 'one2' , 'two2' , 'two1' ] ) . toContainEqual (
369
378
await efs . readFile ( 'test' , { encoding : 'utf-8' } ) ,
370
- ) . toHaveLength ( 4 ) ;
379
+ ) ;
371
380
expect ( await totalINodes ( iNodeMgr ) ) . toEqual ( 2 ) ;
372
381
} ) ,
373
- { numRuns : 20 , interruptAfterTimeLimit } ,
382
+ { numRuns : 50 , interruptAfterTimeLimit } ,
374
383
) ;
375
384
} ) ;
376
385
test ( 'EncryptedFS.appendFile' , async ( ) => {
377
386
await fc . assert (
378
387
fc . asyncProperty ( fc . scheduler ( ) , async ( s ) => {
388
+ // Concurrent appends results in mutually exclusive writes
379
389
await efs . writeFile ( 'test' , 'original' ) ;
380
390
381
391
const prom = Promise . all ( [
0 commit comments