Skip to content

Commit 6b55b3a

Browse files
committed
test(json-crdt): 💍 run latest editing traces and run fuzzer traces
1 parent 2587356 commit 6b55b3a

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"js-base64": "^3.7.2",
118118
"js-sdsl": "^4.4.0",
119119
"jsbi": "^4.3.0",
120-
"json-crdt-traces": "https://github.com/streamich/json-crdt-traces#5f68a13baf798897d39b87d7028b0b3cd5a50a6c",
120+
"json-crdt-traces": "https://github.com/streamich/json-crdt-traces#02718a7a5d09e0dc6c31ea7d45a9ce3cbb0bf085",
121121
"json-logic-js": "^2.0.1",
122122
"json-pack-napi": "^0.0.2",
123123
"load-script": "^2.0.0",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs';
3+
import {Patch} from '../../../json-crdt-patch';
4+
import {CborDecoder} from '../../../json-pack/cbor/CborDecoder';
5+
import {Model} from '../../model';
6+
import {bufferToUint8Array} from '../../../util/buffers/bufferToUint8Array';
7+
8+
export const loadFuzzerTrace = (traceName: string): [batch: Patch[], model: Model] => {
9+
const root = path.resolve(__dirname, '..', '..', '..', '..');
10+
const dir = path.join(root, 'node_modules', 'json-crdt-traces', 'traces', 'fuzzer', 'processed', traceName);
11+
const patchFile = path.join(dir, 'patches.bin');
12+
const modelFile = path.join(dir, 'model.bin');
13+
const buf = fs.readFileSync(patchFile);
14+
const modelBuf = bufferToUint8Array(fs.readFileSync(modelFile));
15+
const model = Model.fromBinary(modelBuf);
16+
const cborDecoder = new CborDecoder();
17+
const data = cborDecoder.read(buf) as Uint8Array[];
18+
const batch = data.map((blob) => Patch.fromBinary(blob));
19+
return [batch, model];
20+
};

src/json-crdt/__tests__/editing-traces.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {sequentialTraceNames, traces} from '../__bench__/util/traces';
33
import {editors} from '../__bench__/util/editors';
44
import {Model} from '../model';
55
import {loadConcurrentTrace} from '../__bench__/util/concurrent-trace';
6+
import {loadFuzzerTrace} from '../__bench__/util/fuzzer-traces';
67

78
describe('sequential traces', () => {
89
const editor = editors['json-joy'];
@@ -15,7 +16,7 @@ describe('sequential traces', () => {
1516
}
1617
});
1718

18-
describe.skip('concurrent traces', () => {
19+
describe('concurrent traces', () => {
1920
const traces: string[] = ['friendsforever'];
2021
for (const traceName of traces) {
2122
test(`"${traceName}" trace`, async () => {
@@ -26,3 +27,27 @@ describe.skip('concurrent traces', () => {
2627
});
2728
}
2829
});
30+
31+
describe('fuzzer traces', () => {
32+
const traces = [
33+
<const>'trace-1',
34+
<const>'trace-2',
35+
<const>'trace-3',
36+
<const>'long',
37+
<const>'short',
38+
<const>'low-concurrency',
39+
<const>'high-concurrency',
40+
<const>'str-only',
41+
<const>'bin-only',
42+
];
43+
44+
for (const traceName of traces) {
45+
test(`"${traceName}" trace`, async () => {
46+
const [batch, doc] = loadFuzzerTrace(traceName);
47+
const model = Model.withLogicalClock(1000000);
48+
model.applyBatch(batch);
49+
expect(Model.fromBinary(model.toBinary()).toString()).toBe(doc.toString());
50+
expect(model.view()).toStrictEqual(doc.view());
51+
});
52+
}
53+
});

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,9 +3664,9 @@ jsesc@^2.5.1:
36643664
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
36653665
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==
36663666

3667-
"json-crdt-traces@https://github.com/streamich/json-crdt-traces#5f68a13baf798897d39b87d7028b0b3cd5a50a6c":
3667+
"json-crdt-traces@https://github.com/streamich/json-crdt-traces#02718a7a5d09e0dc6c31ea7d45a9ce3cbb0bf085":
36683668
version "0.0.1"
3669-
resolved "https://github.com/streamich/json-crdt-traces#5f68a13baf798897d39b87d7028b0b3cd5a50a6c"
3669+
resolved "https://github.com/streamich/json-crdt-traces#02718a7a5d09e0dc6c31ea7d45a9ce3cbb0bf085"
36703670

36713671
json-logic-js@^2.0.1:
36723672
version "2.0.2"

0 commit comments

Comments
 (0)