-
Notifications
You must be signed in to change notification settings - Fork 557
test(ordered-collection): Add Fuzz testing for ConsensusOrderedCollection #25829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scottn12
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
scottn12:ordered-collection-fuzz
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+229
−1
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2484567
add fuzz tests to ordered collection
scottn12 6233190
change applyStashedOp to empty implementation
scottn12 5640eb1
remove comment
scottn12 b6909df
Update packages/dds/ordered-collection/src/test/fuzzUtils.ts
scottn12 c513c8f
include job tracking in assertEqualConsensusOrderedCollections
scottn12 acbd61e
Merge branch 'main' into ordered-collection-fuzz
scottn12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/dds/ordered-collection/src/test/consensusOrderedCollection.fuzz.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
scottn12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export const _dirname = __dirname; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) => { | ||
scottn12 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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(), | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/completeops depend on the distributed state (i.e.jobTracking,acquireId) that are lost/changed during rehydration. In theory, we may be able to apply stashedaddops 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.