Skip to content

Commit 6fa2008

Browse files
Local Server Stress: Reuse DDSFuzzState per channel to allow mutation (#24952)
This change is primarily to support adding tree to the local server stress harness, as the tree model mutates the state to store the current view. This change is also inline with the design of the fuzz harness which support arbitrary state mutation.
1 parent 4d8f694 commit 6fa2008

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

packages/test/local-server-stress-tests/src/ddsOperations.ts

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const createDDSClient = (channel: IChannel): DDSClient<IChannelFactory> => {
4040
};
4141
};
4242

43+
/**
44+
* we use a weak map here, so the lifetime of the DDS state is bound to the channel
45+
* itself, so after the channel is no longer needed the state can also be garbage collected.
46+
*/
47+
const channelToDdsState = new WeakMap<IChannel, DDSFuzzTestState<IChannelFactory>>();
48+
4349
export const covertLocalServerStateToDdsState = async (
4450
state: LocalServerStressState,
4551
): Promise<DDSFuzzTestState<IChannelFactory>> => {
@@ -50,38 +56,45 @@ export const covertLocalServerStateToDdsState = async (
5056
(v) => v.handle !== undefined,
5157
),
5258
];
53-
return {
54-
clients: makeUnreachableCodePathProxy("clients"),
55-
client: createDDSClient(state.channel),
56-
containerRuntimeFactory: makeUnreachableCodePathProxy("containerRuntimeFactory"),
57-
isDetached: state.client.container.attachState === AttachState.Detached,
58-
summarizerClient: makeUnreachableCodePathProxy("containerRuntimeFactory"),
59-
random: {
60-
...state.random,
61-
handle: () => {
62-
/**
63-
* here we do some funky stuff with handles so we can serialize them like json for output, but not bind them,
64-
* as they may not be attached. look at the reduce code to see how we deserialized these fake handles into real
65-
* handles.
66-
*/
67-
const { tag, handle } = state.random.pick(allHandles);
68-
const realHandle = toFluidHandleInternal(handle);
69-
return {
70-
tag,
71-
absolutePath: realHandle.absolutePath,
72-
get [fluidHandleSymbol]() {
73-
return realHandle[fluidHandleSymbol];
74-
},
75-
async get() {
76-
return realHandle.get();
77-
},
78-
get isAttached() {
79-
return realHandle.isAttached;
80-
},
81-
};
82-
},
59+
60+
const random = {
61+
...state.random,
62+
handle: () => {
63+
/**
64+
* here we do some funky stuff with handles so we can serialize them like json for output, but not bind them,
65+
* as they may not be attached. look at the reduce code to see how we deserialized these fake handles into real
66+
* handles.
67+
*/
68+
const { tag, handle } = state.random.pick(allHandles);
69+
const realHandle = toFluidHandleInternal(handle);
70+
return {
71+
tag,
72+
absolutePath: realHandle.absolutePath,
73+
get [fluidHandleSymbol]() {
74+
return realHandle[fluidHandleSymbol];
75+
},
76+
async get() {
77+
return realHandle.get();
78+
},
79+
get isAttached() {
80+
return realHandle.isAttached;
81+
},
82+
};
8383
},
8484
};
85+
86+
const baseState = {
87+
...(channelToDdsState.get(state.channel) ?? {
88+
clients: makeUnreachableCodePathProxy("clients"),
89+
client: createDDSClient(state.channel),
90+
containerRuntimeFactory: makeUnreachableCodePathProxy("containerRuntimeFactory"),
91+
isDetached: state.client.container.attachState === AttachState.Detached,
92+
summarizerClient: makeUnreachableCodePathProxy("containerRuntimeFactory"),
93+
}),
94+
random,
95+
};
96+
channelToDdsState.set(state.channel, baseState);
97+
return baseState;
8598
};
8699

87100
export const DDSModelOpGenerator: AsyncGenerator<DDSModelOp, LocalServerStressState> = async (

0 commit comments

Comments
 (0)