Skip to content

Commit

Permalink
tests: fixing test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Aug 18, 2022
1 parent 82550bc commit b90fddf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tests/EncryptedFS.concurrent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
{ status: 'fulfilled', value: undefined },
]);
// All A, in multiples of 5
expect(contents).toMatch(RegExp('^[^A]*((AAAAA)+[^A]*)$'));
expect(contents).toMatch(RegExp('^(AAAAA)*$'));
// Contents length between 0 and 10*5
expect(contents.length).toBeGreaterThanOrEqual(0);
expect(contents.length).toBeLessThanOrEqual(50);
Expand Down Expand Up @@ -2977,7 +2977,7 @@ describe(`${EncryptedFS.name} Concurrency`, () => {
{ status: 'fulfilled', value: undefined },
]);
// All A, in multiples of 5
expect(contents).toMatch(RegExp('^[^A]*((AAAAA)+[^A]*)$'));
expect(contents).toMatch(RegExp('^(AAAAA)*$'));
// Contents length between 0 and 10*5
expect(contents.length).toBeGreaterThanOrEqual(0);
expect(contents.length).toBeLessThanOrEqual(50);
Expand Down
32 changes: 22 additions & 10 deletions tests/inodes/INodeManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pathNode from 'path';
import fs from 'fs';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
import { ErrorDBTransactionConflict } from '@matrixai/db/dist/errors';
import INodeManager from '@/inodes/INodeManager';
import * as utils from '@/utils';
import * as permissions from '@/permissions';
Expand Down Expand Up @@ -89,16 +90,27 @@ describe('INodeManager', () => {
await iNodeMgr.withTransactionF(async (tran) => {
await tran.put([...iNodeMgr.mgrDbPath, 'test'], 0);
});
await Promise.all([
iNodeMgr.withTransactionF(async (tran) => {
const num = (await tran.get<number>([...iNodeMgr.mgrDbPath, 'test']))!;
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
}),
iNodeMgr.withTransactionF(async (tran) => {
const num = (await tran.get<number>([...iNodeMgr.mgrDbPath, 'test']))!;
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
}),
]);
try {
await Promise.all([
iNodeMgr.withTransactionF(async (tran) => {
const num = (await tran.get<number>([
...iNodeMgr.mgrDbPath,
'test',
]))!;
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
}),
iNodeMgr.withTransactionF(async (tran) => {
const num = (await tran.get<number>([
...iNodeMgr.mgrDbPath,
'test',
]))!;
await tran.put([...iNodeMgr.mgrDbPath, 'test'], num + 1);
}),
]);
} catch (e) {
// We expect a conflict.
if (!(e instanceof ErrorDBTransactionConflict)) throw e;
}
await iNodeMgr.withTransactionF(async (tran) => {
const num = (await tran.get<number>([...iNodeMgr.mgrDbPath, 'test']))!;
// Race condition clobbers the counter
Expand Down

0 comments on commit b90fddf

Please sign in to comment.