Skip to content

Commit 633e03c

Browse files
committed
tests: fixing test failures
fix: `tests/inodes/INodeManager.test.ts` change to using `await expect().rejects.toThrow`
1 parent 823c1d0 commit 633e03c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

tests/EncryptedFS.concurrent.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
29412941
{ status: 'fulfilled', value: undefined },
29422942
]);
29432943
// All A, in multiples of 5
2944-
expect(contents).toMatch(RegExp('^[^A]*((AAAAA)+[^A]*)$'));
2944+
expect(contents).toMatch(RegExp('^(AAAAA)*$'));
29452945
// Contents length between 0 and 10*5
29462946
expect(contents.length).toBeGreaterThanOrEqual(0);
29472947
expect(contents.length).toBeLessThanOrEqual(50);
@@ -2977,7 +2977,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
29772977
{ status: 'fulfilled', value: undefined },
29782978
]);
29792979
// All A, in multiples of 5
2980-
expect(contents).toMatch(RegExp('^[^A]*((AAAAA)+[^A]*)$'));
2980+
expect(contents).toMatch(RegExp('^(AAAAA)*$'));
29812981
// Contents length between 0 and 10*5
29822982
expect(contents.length).toBeGreaterThanOrEqual(0);
29832983
expect(contents.length).toBeLessThanOrEqual(50);

tests/inodes/INodeManager.test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'os';
22
import pathNode from 'path';
33
import fs from 'fs';
44
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
5-
import { DB } from '@matrixai/db';
5+
import { DB, errors as dbErrors } from '@matrixai/db';
66
import INodeManager from '@/inodes/INodeManager';
77
import * as utils from '@/utils';
88
import * as permissions from '@/permissions';
@@ -89,16 +89,24 @@ describe('INodeManager', () => {
8989
await iNodeMgr.withTransactionF(async (tran) => {
9090
await tran.put([...iNodeMgr.mgrDbPath, 'test'], 0);
9191
});
92-
await Promise.all([
93-
iNodeMgr.withTransactionF(async (tran) => {
94-
const num = (await tran.get<number>([...iNodeMgr.mgrDbPath, 'test']))!;
95-
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
96-
}),
97-
iNodeMgr.withTransactionF(async (tran) => {
98-
const num = (await tran.get<number>([...iNodeMgr.mgrDbPath, 'test']))!;
99-
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
100-
}),
101-
]);
92+
await expect(
93+
Promise.all([
94+
iNodeMgr.withTransactionF(async (tran) => {
95+
const num = (await tran.get<number>([
96+
...iNodeMgr.mgrDbPath,
97+
'test',
98+
]))!;
99+
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
100+
}),
101+
iNodeMgr.withTransactionF(async (tran) => {
102+
const num = (await tran.get<number>([
103+
...iNodeMgr.mgrDbPath,
104+
'test',
105+
]))!;
106+
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
107+
}),
108+
]),
109+
).rejects.toThrow(dbErrors.ErrorDBTransactionConflict);
102110
await iNodeMgr.withTransactionF(async (tran) => {
103111
const num = (await tran.get<number>([...iNodeMgr.mgrDbPath, 'test']))!;
104112
// Race condition clobbers the counter

0 commit comments

Comments
 (0)