Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dds/ordered-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"@arethetypeswrong/cli": "^0.17.1",
"@biomejs/biome": "~1.9.3",
"@fluid-internal/mocha-test-setup": "workspace:~",
"@fluid-private/stochastic-test-utils": "workspace:~",
"@fluid-private/test-dds-utils": "workspace:~",
"@fluid-tools/build-cli": "^0.58.3",
"@fluidframework/build-common": "^2.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class ConsensusOrderedCollection<T = any>
}

protected applyStashedOp(): void {
throw new Error("not implemented");
// empty implementation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just for testing purposes? Or is nothing actually the right thing to do? I vaguely recall something about this, but I could be misremembering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helpful for local server stress tests (not in this PR yet) since we can't easily disable rehydration scenarios, so throwing an error would prevent us from integrating this DDS into those tests.

I believe throwing/empty implementation should be correct. acquire/release/complete ops depend on the distributed state (i.e. jobTracking, acquireId) that are lost/changed during rehydration. In theory, we may be able to apply stashed add ops since they do not rely on the distributed state, but dropping them should also be okay since they were not ack'd, so the item was never added and we will stay consistent with the distributed state.

The other consensus-based DDSes also don't apply stashed ops (either throw or have an empty implementation), so this would be consistent with those DDSes.

}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import { createDDSFuzzSuite } from "@fluid-private/test-dds-utils";
import { FlushMode } from "@fluidframework/runtime-definitions/internal";

import { baseConsensusOrderedCollectionModel, defaultOptions } from "./fuzzUtils.js";

describe("ConsensusOrderedCollection fuzz testing", () => {
createDDSFuzzSuite(baseConsensusOrderedCollectionModel, {
...defaultOptions,
// Uncomment this line to replay a specific seed:
// replay: 0,
// This can be useful for quickly minimizing failure json while attempting to root-cause a failure.
});
});

describe("ConsensusOrderedCollection fuzz testing with rebasing", () => {
createDDSFuzzSuite(baseConsensusOrderedCollectionModel, {
...defaultOptions,
containerRuntimeOptions: {
flushMode: FlushMode.TurnBased,
enableGroupedBatching: true,
},
rebaseProbability: 0.15,
// Uncomment this line to replay a specific seed:
// replay: 0,
// This can be useful for quickly minimizing failure json while attempting to root-cause a failure.
});
});
13 changes: 13 additions & 0 deletions packages/dds/ordered-collection/src/test/dirname.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

// Problem:
// - `__dirname` is not defined in ESM
// - `import.meta.url` is not defined in CJS
// Solution:
// - Export '__dirname' from a .cjs file in the same directory.
//
// Note that *.cjs files are always CommonJS, but can be imported from ESM.
export const _dirname = __dirname;
169 changes: 169 additions & 0 deletions packages/dds/ordered-collection/src/test/fuzzUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import { strict as assert } from "node:assert";
import * as path from "node:path";

import type {
AsyncGenerator as Generator,
Reducer,
} from "@fluid-private/stochastic-test-utils";
import {
combineReducers,
createWeightedAsyncGenerator as createWeightedGenerator,
makeRandom,
takeAsync as take,
} from "@fluid-private/stochastic-test-utils";
import type {
DDSFuzzModel,
DDSFuzzSuiteOptions,
DDSFuzzTestState,
} from "@fluid-private/test-dds-utils";

import { ConsensusQueueFactory } from "../consensusOrderedCollectionFactory.js";
import type { IConsensusOrderedCollection } from "../interfaces.js";
import { ConsensusResult } from "../interfaces.js";

import { _dirname } from "./dirname.cjs";

/**
* Config options for generating ConsensusOrderedCollection operations
*/
interface ConsensusOrderedCollectionValueConfig {
/**
* Number of values to be generated for the pool
*/
valuePoolSize?: number;
/**
* Length of value strings
*/
valueStringLength?: number;
}

const valueConfigs: Required<ConsensusOrderedCollectionValueConfig> = {
valuePoolSize: 3,
valueStringLength: 5,
};

/**
* Default options for ConsensusOrderedCollection fuzz testing
*/
export const defaultOptions: Partial<DDSFuzzSuiteOptions> = {
validationStrategy: { type: "fixedInterval", interval: 10 },
clientJoinOptions: {
maxNumberOfClients: 6,
clientAddProbability: 0.05,
},
defaultTestCount: 100,
saveFailures: { directory: path.join(_dirname, "../../src/test/results") },
};

type FuzzTestState = DDSFuzzTestState<ConsensusQueueFactory>;

export interface AddOperation {
type: "add";
value: string;
}

export interface AcquireOperation {
type: "acquire";
resultType: ConsensusResult;
}

/**
* Represents ConsensusOrderedCollection operation types for fuzz testing
*/
export type ConsensusOrderedCollectionOperation = AddOperation | AcquireOperation;

function makeOperationGenerator(): Generator<
ConsensusOrderedCollectionOperation,
FuzzTestState
> {
type OpSelectionState = FuzzTestState & {
itemValue: string;
};

const valuePoolRandom = makeRandom(0);
const dedupe = <T>(arr: T[]): T[] => [...new Set(arr)];
const valuePool = dedupe(
Array.from({ length: valueConfigs.valuePoolSize }, () =>
valuePoolRandom.string(valueConfigs.valueStringLength),
),
);

async function add(state: OpSelectionState): Promise<AddOperation> {
return {
type: "add",
value: state.itemValue,
};
}

async function acquire(state: OpSelectionState): Promise<AcquireOperation> {
return {
type: "acquire",
resultType: state.random.pick([ConsensusResult.Complete, ConsensusResult.Release]),
};
}

const clientBaseOperationGenerator = createWeightedGenerator<
ConsensusOrderedCollectionOperation,
OpSelectionState
>([
[add, 1],
[acquire, 1],
]);

return async (state: FuzzTestState) =>
clientBaseOperationGenerator({
...state,
itemValue: state.random.pick(valuePool),
});
}

function makeReducer(): Reducer<ConsensusOrderedCollectionOperation, FuzzTestState> {
const reducer = combineReducers<ConsensusOrderedCollectionOperation, FuzzTestState>({
add: ({ client }, { value }) => {
client.channel.add(value).catch((error) => {
throw error;
});
},
acquire: ({ client }, { resultType }) => {
client.channel
.acquire(async (value) => {
return resultType;
})
.catch((error) => {
throw error;
});
},
});
return reducer;
}

function assertEqualConsensusOrderedCollections(
a: IConsensusOrderedCollection,
b: IConsensusOrderedCollection,
): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
const aData = (a as any).data;
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
const bData = (b as any).data;
assert.deepEqual(aData, bData, "Internal data properties should be equal");
}

/**
* Base fuzz model for ConsensusOrderedCollection
*/
export const baseConsensusOrderedCollectionModel: DDSFuzzModel<
ConsensusQueueFactory,
ConsensusOrderedCollectionOperation,
FuzzTestState
> = {
workloadName: "default configuration",
generatorFactory: () => take(100, makeOperationGenerator()),
reducer: makeReducer(),
validateConsistency: (a, b) => assertEqualConsensusOrderedCollections(a.channel, b.channel),
factory: new ConsensusQueueFactory(),
};
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading