@@ -240,6 +240,9 @@ mod tests {
240240 AgentDescription , DescriptionValueType , StartSettings ,
241241 } ;
242242 use std:: collections:: HashMap ;
243+ use std:: thread;
244+ use std:: thread:: sleep;
245+ use std:: time:: Duration ;
243246 use tracing_test:: traced_test;
244247
245248 // TODO: tests below are testing not only the builder but also the sub-agent start/stop behavior.
@@ -277,10 +280,13 @@ mod tests {
277280 started_client. should_stop ( 1 ) ;
278281
279282 // Infra Agent OpAMP no final stop nor health, just after stopping on reload
280- opamp_builder. should_build_and_start (
283+ // TODO: We should discussed if this is a valid approach once we refactor the unit tests
284+ // Build an OpAMP Client and let it run so the publisher is not dropped
285+ opamp_builder. should_build_and_start_and_run (
281286 sub_agent_id. clone ( ) ,
282287 start_settings_infra,
283288 started_client,
289+ Duration :: from_millis ( 10 ) ,
284290 ) ;
285291
286292 let mut instance_id_getter = MockInstanceIDGetterMock :: new ( ) ;
@@ -320,12 +326,15 @@ mod tests {
320326 Arc :: new ( signature_validator) ,
321327 ) ;
322328
323- on_host_builder
329+ let agent = on_host_builder
324330 . build ( sub_agent_id, & sub_agent_config, opamp_publisher)
325331 . unwrap ( )
326- . run ( )
327- . stop ( )
328- . unwrap ( ) ;
332+ . run ( ) ;
333+
334+ // Force OpAMP Publisher drop error
335+ // sleep(Duration::from_millis(30));
336+
337+ agent. stop ( ) . unwrap ( ) ;
329338 }
330339
331340 #[ traced_test]
@@ -375,10 +384,13 @@ mod tests {
375384 started_client. should_update_effective_config ( 1 ) ;
376385 started_client. should_stop ( 1 ) ;
377386
378- opamp_builder. should_build_and_start (
387+ // TODO: We should discussed if this is a valid approach once we refactor the unit tests
388+ // Build an OpAMP Client and let it run so the publisher is not dropped
389+ opamp_builder. should_build_and_start_and_run (
379390 sub_agent_id. clone ( ) ,
380391 start_settings_infra,
381392 started_client,
393+ Duration :: from_millis ( 10 ) ,
382394 ) ;
383395
384396 effective_agent_assembler. should_assemble_agent (
@@ -412,6 +424,10 @@ mod tests {
412424 . build ( sub_agent_id, & sub_agent_config, opamp_publisher)
413425 . expect ( "Subagent build should be OK" ) ;
414426 let started_sub_agent = sub_agent. run ( ) ; // Running the sub-agent should report the failed configuration.
427+
428+ // Force OpAMP Publisher drop error
429+ // sleep(Duration::from_millis(20));
430+
415431 started_sub_agent. stop ( ) . unwrap ( ) ;
416432 }
417433
0 commit comments