Skip to content

Commit 85c3d42

Browse files
wip
1 parent b92a838 commit 85c3d42

File tree

2 files changed

+58
-69
lines changed

2 files changed

+58
-69
lines changed

packages/dds/map/src/test/directoryOracle.ts

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
33
* Licensed under the MIT License.
44
*/
5-
6-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
7-
85
import { strict as assert } from "node:assert";
96

7+
import type { IEventThisPlaceHolder } from "@fluidframework/core-interfaces";
8+
109
import type {
1110
IDirectory,
1211
IDirectoryValueChanged,
@@ -28,97 +27,87 @@ export class SharedDirectoryOracle {
2827
this.sharedDir.on("subDirectoryDeleted", this.onSubDirDeleted);
2928
this.sharedDir.on("containedValueChanged", this.onContainedValueChanged);
3029

31-
this.captureInitialSnapshot(sharedDir);
30+
this.takeSnapshot(sharedDir);
3231
}
3332

34-
private captureInitialSnapshot(dir: IDirectory): void {
35-
// Capture keys
36-
for (const [key, value] of dir.entries()) {
37-
const pathKey = dir.absolutePath === "/" ? `/${key}` : `${dir.absolutePath}/${key}`;
38-
39-
this.model.set(pathKey, value);
40-
}
41-
42-
for (const [, subDir] of dir.subdirectories()) {
43-
// Just recurse to capture keys inside the subdir
44-
this.captureInitialSnapshot(subDir);
33+
private takeSnapshot(dir: ISharedDirectory | IDirectory): void {
34+
for (const [k, v] of this.sharedDir.entries()) {
35+
this.model.set(k, v);
4536
}
4637
}
4738

48-
private readonly onValueChanged = (change: IDirectoryValueChanged) => {
39+
private readonly onValueChanged = (
40+
changed: IDirectoryValueChanged,
41+
local: boolean,
42+
target: IEventThisPlaceHolder,
43+
): void => {
4944
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
50-
const { key, previousValue } = change;
51-
const path = change.path ?? "";
52-
53-
const pathKey = path === "/" ? `/${key}` : `${path}/${key}`;
54-
55-
assert.strictEqual(
56-
previousValue,
57-
this.model.get(pathKey),
58-
`Mismatch on previous value for key="${key}"`,
59-
);
45+
const { path, key, previousValue } = changed;
46+
const fullPath = path === "/" ? `/${key}` : `${path}/${key}`;
47+
48+
if (this.model.has(fullPath)) {
49+
const prevVal = this.model.get(fullPath);
50+
assert.strictEqual(
51+
prevVal,
52+
previousValue,
53+
`previous value mismatch at ${fullPath}: expected: ${prevVal}, actual: ${previousValue}`,
54+
);
55+
}
6056

61-
const fuzzDir = this.sharedDir.getWorkingDirectory(path);
62-
if (!fuzzDir) return;
57+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
58+
const newVal = this.sharedDir.get(fullPath);
6359

64-
if (fuzzDir.has(key)) {
65-
this.model.set(pathKey, fuzzDir.get(key));
60+
if (newVal === undefined) {
61+
// deletion
62+
this.model.delete(fullPath);
6663
} else {
67-
this.model.delete(pathKey);
64+
this.model.set(fullPath, newVal);
6865
}
6966
};
7067

71-
private readonly onClear = (local: boolean) => {
68+
private readonly onClear = (local: boolean, target: IEventThisPlaceHolder): void => {
7269
this.model.clear();
7370
};
7471

7572
private readonly onSubDirCreated = (
76-
subdirName: string,
73+
path: string,
7774
local: boolean,
78-
target: ISharedDirectory,
79-
) => {
80-
const { absolutePath } = target;
81-
if (!this.model.has(`${absolutePath}${subdirName}`)) {
82-
this.model.set(`${absolutePath}${subdirName}`, undefined);
83-
}
75+
target: IEventThisPlaceHolder,
76+
): void => {
77+
this.model.set(path, undefined);
8478
};
8579

86-
private readonly onSubDirDeleted = (path: string) => {
87-
const absPath = path.startsWith("/") ? path : `/${path}`;
88-
for (const key of [...this.model.keys()]) {
89-
if (key.startsWith(absPath)) {
90-
const deleted = this.model.delete(key);
91-
if (!deleted) {
92-
assert("not deleted");
93-
}
94-
}
95-
}
80+
private readonly onSubDirDeleted = (
81+
path: string,
82+
local: boolean,
83+
target: IEventThisPlaceHolder,
84+
): void => {
85+
this.model.delete(path);
9686
};
9787

9888
private readonly onContainedValueChanged = (
99-
change: IValueChanged,
89+
changed: IValueChanged,
10090
local: boolean,
101-
target: IDirectory,
102-
) => {
91+
target: IEventThisPlaceHolder,
92+
): void => {
10393
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
104-
const { key, previousValue } = change;
105-
const { absolutePath } = target;
106-
107-
const pathKey = absolutePath === "/" ? `/${key}` : `${absolutePath}/${key}`;
108-
109-
assert.strictEqual(
110-
previousValue,
111-
this.model.get(pathKey),
112-
`Mismatch on previous value for key="${key}"`,
113-
);
94+
const { key, previousValue } = changed;
95+
96+
if (this.model.has(key)) {
97+
const prevVal = this.model.get(key);
98+
assert.strictEqual(
99+
prevVal,
100+
previousValue,
101+
`contained previous value mismatch at ${key}: expected: ${prevVal}, actual: ${previousValue}`,
102+
);
103+
}
114104

115105
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
116-
const newValue = target.get(key);
117-
118-
if (newValue === undefined) {
119-
this.model.delete(pathKey);
106+
const newVal = this.sharedDir.get(key);
107+
if (newVal === undefined) {
108+
this.model.delete(key);
120109
} else {
121-
this.model.set(pathKey, newValue);
110+
this.model.set(key, newVal);
122111
}
123112
};
124113

packages/dds/map/src/test/mocha/directoryFuzzTests.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type DDSFuzzHarnessEvents,
1212
type DDSFuzzModel,
1313
createDDSFuzzSuite,
14+
registerOracle,
1415
} from "@fluid-private/test-dds-utils";
1516
import { FlushMode } from "@fluidframework/runtime-definitions/internal";
1617

@@ -35,6 +36,7 @@ oracleEmitter.on("clientCreate", (client) => {
3536
const channel = client.channel as ISharedDirectoryWithOracle;
3637
const directroyOracle = new SharedDirectoryOracle(channel);
3738
channel.sharedDirectoryOracle = directroyOracle;
39+
registerOracle(directroyOracle);
3840
});
3941

4042
describe("SharedDirectory fuzz Create/Delete concentrated", () => {
@@ -109,7 +111,6 @@ describe("SharedDirectory fuzz Create/Delete concentrated", () => {
109111
},
110112
defaultTestCount: 200,
111113
emitter: oracleEmitter,
112-
// emitter: oracleEmitter,
113114
// Uncomment this line to replay a specific seed from its failure file:
114115
// replay: 0,
115116
saveFailures: {
@@ -125,7 +126,6 @@ describe("SharedDirectory fuzz", () => {
125126
type: "fixedInterval",
126127
interval: dirDefaultOptions.validateInterval,
127128
},
128-
skipMinimization: true,
129129
reconnectProbability: 0.15,
130130
numberOfClients: 3,
131131
clientJoinOptions: {

0 commit comments

Comments
 (0)