Skip to content

Commit a2915f8

Browse files
Copilotpubkey
andauthored
Add optional password param to runPerformanceTests for encryption benchmarking (#8135)
* Initial plan * Add optional password param to runPerformanceTests for encryption support and add test:performance:memory:crypto-js npm script Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com> * Simplify STORAGE_PASSWORD ternary per code review Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
1 parent 835c7d4 commit a2915f8

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@
476476
"test:performance:dexie": "npm run transpile && cross-env DEFAULT_STORAGE=dexie CI=true karma start ./config/karma.performance.conf.cjs --single-run",
477477
"test:performance:memory:browser": "npm run transpile && cross-env DEFAULT_STORAGE=memory CI=true karma start ./config/karma.performance.conf.cjs --single-run",
478478
"test:performance:memory:node": "npm run transpile && cross-env DEFAULT_STORAGE=memory mocha --config ./config/.mocharc.cjs ./test_tmp/performance.test.js --unhandled-rejections=strict --expose-gc",
479+
"test:performance:memory:crypto-js": "npm run transpile && cross-env DEFAULT_STORAGE=memory STORAGE_PASSWORD=test-password mocha --config ./config/.mocharc.cjs ./test_tmp/performance.test.js --unhandled-rejections=strict --expose-gc",
479480
"test:performance:memory:bun": "npm run transpile && cross-env DEFAULT_STORAGE=memory bun run ./node_modules/mocha/bin/mocha test_tmp/performance.test.js --bail",
480481
"test:performance:memory:deno": "npm run transpile && cross-env DEFAULT_STORAGE=memory deno run --allow-env --allow-read -A npm:mocha test/performance.test.ts --bail",
481482
"test:performance:foundationdb": "npm run transpile && cross-env DEFAULT_STORAGE=foundationdb mocha --config ./config/.mocharc.cjs ./test_tmp/performance.test.js --unhandled-rejections=strict --expose-gc",

src/plugins/test-utils/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function getEnvVariables() {
4040
const ret: any = {};
4141
[
4242
'DEFAULT_STORAGE',
43-
'NODE_ENV'
43+
'NODE_ENV',
44+
'STORAGE_PASSWORD'
4445
].forEach(k => {
4546
ret[k] = Deno.env.get(k);
4647
});

src/plugins/test-utils/performance.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export type PerformanceTestConfig = {
5353
* @default true
5454
*/
5555
log?: boolean;
56+
/**
57+
* If set, the database will be created with encryption
58+
* and the schema will mark applicable fields as encrypted.
59+
*/
60+
password?: any;
5661
};
5762

5863
export type PerformanceTestResult = {
@@ -84,7 +89,8 @@ export async function runPerformanceTests(
8489
parallelQueryAmount = 4,
8590
insertBatches = 6,
8691
waitBetweenTests = 100,
87-
log = true
92+
log = true,
93+
password
8894
} = config;
8995

9096
const totalTimes: { [k: string]: number[]; } = {};
@@ -121,6 +127,15 @@ export async function runPerformanceTests(
121127

122128
// create database
123129
const schema = averageSchema();
130+
if (password) {
131+
schema.encrypted = ['deep', 'list'];
132+
schema.indexes = schema.indexes!.filter(index => {
133+
if (typeof index === 'string') {
134+
return !index.startsWith('deep.');
135+
}
136+
return !index.some(field => field.startsWith('deep.'));
137+
});
138+
}
124139
let collection: RxCollection<AverageSchemaDocumentType>;
125140
async function createDbWithCollections() {
126141
if (collection) {
@@ -137,7 +152,8 @@ export async function runPerformanceTests(
137152
* creation time.
138153
*/
139154
multiInstance: false,
140-
storage
155+
storage,
156+
password
141157
});
142158

143159
// create collections

test/performance.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
} from '../plugins/core/index.mjs';
44
import * as assert from 'assert';
55
import {
6+
ENV_VARIABLES,
7+
getEncryptedStorage,
68
isFastMode,
79
isDeno,
810
runPerformanceTests
@@ -31,10 +33,13 @@ describe('performance.test.ts', () => {
3133
this.timeout(500 * 1000);
3234
const runs = isFastMode() ? 1 : 40;
3335
const perfStorage = config.storage.getPerformanceStorage();
36+
const password = ENV_VARIABLES.STORAGE_PASSWORD || undefined;
37+
const storage = password ? getEncryptedStorage(perfStorage.storage) : perfStorage.storage;
38+
const description = password ? perfStorage.description + '-encrypted' : perfStorage.description;
3439
await runPerformanceTests(
35-
perfStorage.storage,
36-
perfStorage.description,
37-
{ runs }
40+
storage,
41+
description,
42+
{ runs, password }
3843
);
3944
});
4045
/**

0 commit comments

Comments
 (0)