@@ -40,6 +40,12 @@ const createDDSClient = (channel: IChannel): DDSClient<IChannelFactory> => {
40
40
} ;
41
41
} ;
42
42
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
+
43
49
export const covertLocalServerStateToDdsState = async (
44
50
state : LocalServerStressState ,
45
51
) : Promise < DDSFuzzTestState < IChannelFactory > > => {
@@ -50,38 +56,45 @@ export const covertLocalServerStateToDdsState = async (
50
56
( v ) => v . handle !== undefined ,
51
57
) ,
52
58
] ;
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
+ } ;
83
83
} ,
84
84
} ;
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 ;
85
98
} ;
86
99
87
100
export const DDSModelOpGenerator : AsyncGenerator < DDSModelOp , LocalServerStressState > = async (
0 commit comments