@@ -22,7 +22,8 @@ mod utils {
2222
2323use futures:: { StreamExt , join} ;
2424use nativelink_config:: schedulers:: {
25- PlatformPropertyAddition , PropertyModification , PropertyModifierSpec , SchedulerSpec , SimpleSpec ,
25+ PlatformPropertyAddition , PlatformPropertyReplacement , PropertyModification ,
26+ PropertyModifierSpec , SchedulerSpec , SimpleSpec ,
2627} ;
2728use nativelink_error:: Error ;
2829use nativelink_macro:: nativelink_test;
@@ -181,7 +182,7 @@ async fn add_action_property_remove_after_add() -> Result<(), Error> {
181182 let context = make_modifier_scheduler ( vec ! [
182183 PropertyModification :: Add ( PlatformPropertyAddition {
183184 name: name. clone( ) ,
184- value: value . clone ( ) ,
185+ value,
185186 } ) ,
186187 PropertyModification :: Remove ( name. clone( ) ) ,
187188 ] ) ;
@@ -210,6 +211,139 @@ async fn add_action_property_remove_after_add() -> Result<(), Error> {
210211 Ok ( ( ) )
211212}
212213
214+ #[ nativelink_test]
215+ async fn add_action_property_replace ( ) -> Result < ( ) , Error > {
216+ let name = "name" . to_string ( ) ;
217+ let new_name = "new_name" . to_string ( ) ;
218+ let value = "value" . to_string ( ) ;
219+ let context = make_modifier_scheduler ( vec ! [ PropertyModification :: Replace (
220+ PlatformPropertyReplacement {
221+ name: name. clone( ) ,
222+ value: None ,
223+ new_name: new_name. clone( ) ,
224+ new_value: None ,
225+ } ,
226+ ) ] ) ;
227+ let mut action_info = make_base_action_info ( UNIX_EPOCH , DigestInfo :: zero_digest ( ) ) ;
228+ Arc :: make_mut ( & mut action_info)
229+ . platform_properties
230+ . insert ( name, value. clone ( ) ) ;
231+ let ( _forward_watch_channel_tx, forward_watch_channel_rx) =
232+ watch:: channel ( Arc :: new ( ActionState {
233+ client_operation_id : OperationId :: default ( ) ,
234+ stage : ActionStage :: Queued ,
235+ action_digest : action_info. unique_qualifier . digest ( ) ,
236+ } ) ) ;
237+ let client_operation_id = OperationId :: default ( ) ;
238+ let ( _, ( passed_client_operation_id, action_info) ) = join ! (
239+ context
240+ . modifier_scheduler
241+ . add_action( client_operation_id. clone( ) , action_info. clone( ) ) ,
242+ context
243+ . mock_scheduler
244+ . expect_add_action( Ok ( Box :: new( TokioWatchActionStateResult :: new(
245+ client_operation_id. clone( ) ,
246+ action_info,
247+ forward_watch_channel_rx
248+ ) ) ) ) ,
249+ ) ;
250+ assert_eq ! ( client_operation_id, passed_client_operation_id) ;
251+ assert_eq ! (
252+ HashMap :: from( [ ( new_name, value) ] ) ,
253+ action_info. platform_properties
254+ ) ;
255+ Ok ( ( ) )
256+ }
257+
258+ #[ nativelink_test]
259+ async fn add_action_property_replace_match_value ( ) -> Result < ( ) , Error > {
260+ let name = "name" . to_string ( ) ;
261+ let new_name = "new_name" . to_string ( ) ;
262+ let value = "value" . to_string ( ) ;
263+ let context = make_modifier_scheduler ( vec ! [ PropertyModification :: Replace (
264+ PlatformPropertyReplacement {
265+ name: name. clone( ) ,
266+ value: Some ( value. clone( ) ) ,
267+ new_name: new_name. clone( ) ,
268+ new_value: None ,
269+ } ,
270+ ) ] ) ;
271+ let mut action_info = make_base_action_info ( UNIX_EPOCH , DigestInfo :: zero_digest ( ) ) ;
272+ Arc :: make_mut ( & mut action_info)
273+ . platform_properties
274+ . insert ( name. clone ( ) , value. clone ( ) ) ;
275+ let ( _forward_watch_channel_tx, forward_watch_channel_rx) =
276+ watch:: channel ( Arc :: new ( ActionState {
277+ client_operation_id : OperationId :: default ( ) ,
278+ stage : ActionStage :: Queued ,
279+ action_digest : action_info. unique_qualifier . digest ( ) ,
280+ } ) ) ;
281+ let client_operation_id = OperationId :: default ( ) ;
282+ let ( _, ( passed_client_operation_id, action_info) ) = join ! (
283+ context
284+ . modifier_scheduler
285+ . add_action( client_operation_id. clone( ) , action_info. clone( ) ) ,
286+ context
287+ . mock_scheduler
288+ . expect_add_action( Ok ( Box :: new( TokioWatchActionStateResult :: new(
289+ client_operation_id. clone( ) ,
290+ action_info,
291+ forward_watch_channel_rx
292+ ) ) ) ) ,
293+ ) ;
294+ assert_eq ! ( client_operation_id, passed_client_operation_id) ;
295+ assert_eq ! (
296+ HashMap :: from( [ ( new_name, value) ] ) ,
297+ action_info. platform_properties
298+ ) ;
299+ Ok ( ( ) )
300+ }
301+
302+ #[ nativelink_test]
303+ async fn add_action_property_replace_value ( ) -> Result < ( ) , Error > {
304+ let name = "name" . to_string ( ) ;
305+ let new_name = "new_name" . to_string ( ) ;
306+ let value = "value" . to_string ( ) ;
307+ let value_two = "value_two" . to_string ( ) ;
308+ let context = make_modifier_scheduler ( vec ! [ PropertyModification :: Replace (
309+ PlatformPropertyReplacement {
310+ name: name. clone( ) ,
311+ value: None ,
312+ new_name: new_name. clone( ) ,
313+ new_value: Some ( value_two. clone( ) ) ,
314+ } ,
315+ ) ] ) ;
316+ let mut action_info = make_base_action_info ( UNIX_EPOCH , DigestInfo :: zero_digest ( ) ) ;
317+ Arc :: make_mut ( & mut action_info)
318+ . platform_properties
319+ . insert ( name. clone ( ) , value. clone ( ) ) ;
320+ let ( _forward_watch_channel_tx, forward_watch_channel_rx) =
321+ watch:: channel ( Arc :: new ( ActionState {
322+ client_operation_id : OperationId :: default ( ) ,
323+ stage : ActionStage :: Queued ,
324+ action_digest : action_info. unique_qualifier . digest ( ) ,
325+ } ) ) ;
326+ let client_operation_id = OperationId :: default ( ) ;
327+ let ( _, ( passed_client_operation_id, action_info) ) = join ! (
328+ context
329+ . modifier_scheduler
330+ . add_action( client_operation_id. clone( ) , action_info. clone( ) ) ,
331+ context
332+ . mock_scheduler
333+ . expect_add_action( Ok ( Box :: new( TokioWatchActionStateResult :: new(
334+ client_operation_id. clone( ) ,
335+ action_info,
336+ forward_watch_channel_rx
337+ ) ) ) ) ,
338+ ) ;
339+ assert_eq ! ( client_operation_id, passed_client_operation_id) ;
340+ assert_eq ! (
341+ HashMap :: from( [ ( new_name, value_two) ] ) ,
342+ action_info. platform_properties
343+ ) ;
344+ Ok ( ( ) )
345+ }
346+
213347#[ nativelink_test]
214348async fn add_action_property_remove ( ) -> Result < ( ) , Error > {
215349 let name = "name" . to_string ( ) ;
@@ -303,3 +437,26 @@ async fn remove_retains_type_in_underlying_manager() -> Result<(), Error> {
303437 assert_eq ! ( Ok ( vec![ name] ) , known_props) ;
304438 Ok ( ( ) )
305439}
440+
441+ #[ nativelink_test]
442+ async fn replace_retains_type_in_underlying_manager ( ) -> Result < ( ) , Error > {
443+ let name = "name" . to_string ( ) ;
444+ let context = make_modifier_scheduler ( vec ! [ PropertyModification :: Replace (
445+ PlatformPropertyReplacement {
446+ name: name. clone( ) ,
447+ value: None ,
448+ new_name: "new_name" . to_string( ) ,
449+ new_value: None ,
450+ } ,
451+ ) ] ) ;
452+ let known_properties = vec ! [ name. clone( ) ] ;
453+ let instance_name_fut = context
454+ . mock_scheduler
455+ . expect_get_known_properties ( Ok ( known_properties) ) ;
456+ let known_props_fut = context
457+ . modifier_scheduler
458+ . get_known_properties ( INSTANCE_NAME ) ;
459+ let ( _, known_props) = join ! ( instance_name_fut, known_props_fut) ;
460+ assert_eq ! ( Ok ( vec![ name] ) , known_props) ;
461+ Ok ( ( ) )
462+ }
0 commit comments