Skip to content

Commit 2e99692

Browse files
committed
tests: inlined interruptAfterTimeLimit and moved scheduleCall to tests/utils.ts
1 parent 55b2718 commit 2e99692

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

Diff for: tests/EncryptedFS.concurrent.test.ts

+46-29
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,18 @@ import * as utils from '@/utils';
1313
import * as constants from '@/constants';
1414
import INodeManager from '@/inodes/INodeManager';
1515
import { promise } from '@/utils';
16-
import { expectError, expectReason, sleep } from './utils';
16+
import { expectError, expectReason, sleep, scheduleCall } from './utils';
1717

1818
describe(`${EncryptedFS.name} Concurrency`, () => {
1919
const logger = new Logger(`${EncryptedFS.name} Concurrency`, LogLevel.WARN, [
2020
new StreamHandler(),
2121
]);
2222
const dbKey: Buffer = utils.generateKeySync(256);
23-
const interruptAfterTimeLimit = globalThis.defaultTimeout - 2000;
2423
let dataDir: string;
2524
let db: DB;
2625
let iNodeMgr: INodeManager;
2726
let efs: EncryptedFS;
2827

29-
const scheduleCall = <T>(
30-
s: fc.Scheduler,
31-
f: () => Promise<T>,
32-
label: string = 'scheduled call',
33-
) => s.schedule(Promise.resolve(label)).then(() => f());
34-
3528
const totalINodes = async (iNodeMgr: INodeManager) => {
3629
let counter = 0;
3730
for await (const _ of iNodeMgr.getAll()) {
@@ -121,7 +114,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
121114
// Cleaning up
122115
await efs.rmdir('dir', { recursive: true });
123116
}),
124-
{ interruptAfterTimeLimit },
117+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
125118
);
126119
});
127120
test('EncryptedFS.open', async () => {
@@ -335,7 +328,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
335328
await efs.close(fd);
336329
}
337330
}),
338-
{ numRuns: 50, interruptAfterTimeLimit },
331+
{
332+
numRuns: 50,
333+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
334+
},
339335
);
340336
});
341337
test('EncryptedFS.write on the same file descriptor', async () => {
@@ -356,7 +352,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
356352
);
357353
await efs.close(fd);
358354
}),
359-
{ numRuns: 20, interruptAfterTimeLimit },
355+
{
356+
numRuns: 20,
357+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
358+
},
360359
);
361360
});
362361
test('EncryptedFS.writeFile', async () => {
@@ -379,7 +378,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
379378
);
380379
expect(await totalINodes(iNodeMgr)).toEqual(2);
381380
}),
382-
{ numRuns: 50, interruptAfterTimeLimit },
381+
{
382+
numRuns: 50,
383+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
384+
},
383385
);
384386
});
385387
test('EncryptedFS.appendFile', async () => {
@@ -408,7 +410,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
408410
await efs.readFile('test', { encoding: 'utf-8' }),
409411
);
410412
}),
411-
{ numRuns: 20, interruptAfterTimeLimit },
413+
{
414+
numRuns: 20,
415+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
416+
},
412417
);
413418
});
414419
test('EncryptedFS.fallocate, EncryptedFS.writeFile, EncryptedFS.write and EncryptedFS.createWriteStream ', async () => {
@@ -451,7 +456,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
451456
// Cleaning up
452457
await efs.rmdir('dir', { recursive: true });
453458
}),
454-
{ interruptAfterTimeLimit },
459+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
455460
);
456461
});
457462
test('EncryptedFS.fallocate and EncryptedFS.writeFile', async () => {
@@ -795,7 +800,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
795800
// Cleaning up
796801
await efs.rmdir('dir', { recursive: true });
797802
}),
798-
{ interruptAfterTimeLimit },
803+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
799804
);
800805
});
801806
test('EncryptedFS.truncate and EncryptedFS.writeFile', async () => {
@@ -1148,7 +1153,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
11481153
// Cleaning up
11491154
await efs.rmdir('dir', { recursive: true });
11501155
}),
1151-
{ interruptAfterTimeLimit },
1156+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
11521157
);
11531158
});
11541159
test('EncryptedFS.ftruncate and EncryptedFS.writeFile', async () => {
@@ -1484,7 +1489,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
14841489
// Cleaning up
14851490
await efs.rmdir('dir', { recursive: true });
14861491
}),
1487-
{ interruptAfterTimeLimit },
1492+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
14881493
);
14891494
});
14901495
test('EncryptedFS.utimes and EncryptedFS.writeFile', async () => {
@@ -1694,7 +1699,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
16941699
// Cleaning up
16951700
await efs.rmdir('dir', { recursive: true });
16961701
}),
1697-
{ interruptAfterTimeLimit },
1702+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
16981703
);
16991704
});
17001705
test('EncryptedFS.lseek and EncryptedFS.writeFile', async () => {
@@ -2126,7 +2131,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
21262131
// Cleaning up
21272132
await efs.rmdir('dir', { recursive: true });
21282133
}),
2129-
{ interruptAfterTimeLimit },
2134+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
21302135
);
21312136
});
21322137
test('EncryptedFS.createReadStream and EncryptedFS.createWriteStream', async () => {
@@ -2632,7 +2637,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
26322637
// Cleaning up
26332638
await efs.rmdir('dir', { recursive: true });
26342639
}),
2635-
{ interruptAfterTimeLimit },
2640+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
26362641
);
26372642
});
26382643
test('EncryptedFS.unlink and EncryptedFS.writeFile', async () => {
@@ -2914,7 +2919,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
29142919
// Cleaning up
29152920
await efs.rmdir('dir', { recursive: true });
29162921
}),
2917-
{ interruptAfterTimeLimit },
2922+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
29182923
);
29192924
});
29202925
test('EncryptedFS.appendFIle and EncryptedFS.writeFile', async () => {
@@ -3264,7 +3269,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
32643269
// Cleaning up
32653270
await efs.rmdir('dir', { recursive: true });
32663271
}),
3267-
{ interruptAfterTimeLimit },
3272+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
32683273
);
32693274
});
32703275
test('EncryptedFS.copyFile and EncryptedFS.writeFile', async () => {
@@ -3604,7 +3609,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
36043609
// Cleaning up
36053610
await efs.rmdir('dir', { recursive: true });
36063611
}),
3607-
{ numRuns: 20, interruptAfterTimeLimit },
3612+
{
3613+
numRuns: 20,
3614+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
3615+
},
36083616
);
36093617
});
36103618
test('EncryptedFS.read and EncryptedFS.write', async () => {
@@ -3645,7 +3653,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
36453653
// Cleaning up
36463654
await efs.rmdir('dir', { recursive: true });
36473655
}),
3648-
{ numRuns: 20, interruptAfterTimeLimit },
3656+
{
3657+
numRuns: 20,
3658+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
3659+
},
36493660
);
36503661
});
36513662
test('EncryptedFS.read and EncryptedFS.write with different fd', async () => {
@@ -3819,7 +3830,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
38193830
// Cleaning up
38203831
await efs.rmdir('dir', { recursive: true });
38213832
}),
3822-
{ interruptAfterTimeLimit },
3833+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
38233834
);
38243835
});
38253836
test('EncryptedFS.mkdir', async () => {
@@ -3921,7 +3932,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
39213932
// Cleaning up
39223933
await efs.rmdir('dir', { recursive: true });
39233934
}),
3924-
{ interruptAfterTimeLimit },
3935+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
39253936
);
39263937
});
39273938
test('EncryptedFS.readdir and EncryptedFS.rmdir', async () => {
@@ -4294,7 +4305,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
42944305
// Cleaning up
42954306
await efs.rmdir('dir', { recursive: true });
42964307
}),
4297-
{ numRuns: 20, interruptAfterTimeLimit },
4308+
{
4309+
numRuns: 20,
4310+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
4311+
},
42984312
);
42994313
});
43004314
});
@@ -4331,7 +4345,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
43314345
// Cleaning up
43324346
await efs.rmdir('dir', { recursive: true });
43334347
}),
4334-
{ interruptAfterTimeLimit },
4348+
{ interruptAfterTimeLimit: globalThis.defaultTimeout - 2000 },
43354349
);
43364350
});
43374351
test('EncryptedFS.symlink and EncryptedFS.symlink', async () => {
@@ -4568,7 +4582,10 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
45684582
// Cleaning up
45694583
await efs.rmdir('dir', { recursive: true });
45704584
}),
4571-
{ numRuns: 20, interruptAfterTimeLimit },
4585+
{
4586+
numRuns: 20,
4587+
interruptAfterTimeLimit: globalThis.defaultTimeout - 2000,
4588+
},
45724589
);
45734590
});
45744591
test('EncryptedFS.link and EncryptedFS.link', async () => {

Diff for: tests/utils.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type EncryptedFS from '@/EncryptedFS';
2+
import type * as fc from 'fast-check';
23
import * as constants from '@/constants';
34

45
/**
@@ -101,6 +102,20 @@ function setId(efs: EncryptedFS, uid: number, gid?: number) {
101102
efs.gid = gid ?? uid;
102103
}
103104

104-
export { expectError, expectReason, createFile, supportedTypes, sleep, setId };
105+
const scheduleCall = <T>(
106+
s: fc.Scheduler,
107+
f: () => Promise<T>,
108+
label: string = 'scheduled call',
109+
) => s.schedule(Promise.resolve(label)).then(() => f());
110+
111+
export {
112+
expectError,
113+
expectReason,
114+
createFile,
115+
supportedTypes,
116+
sleep,
117+
setId,
118+
scheduleCall,
119+
};
105120

106121
export type { FileTypes };

0 commit comments

Comments
 (0)