@@ -200,6 +200,19 @@ mod tests {
200
200
)
201
201
}
202
202
203
+ async fn test_component_reload ( file : & mut File ,
204
+ expected_component : & ComponentKey ,
205
+ timeout : Duration ,
206
+ mut receiver : SignalRx ) -> bool {
207
+ file. write_all ( & [ 0 ] ) . unwrap ( ) ;
208
+ file. sync_all ( ) . unwrap ( ) ;
209
+
210
+ matches ! (
211
+ tokio:: time:: timeout( timeout, receiver. recv( ) ) . await ,
212
+ Ok ( Ok ( crate :: signal:: SignalTo :: ReloadComponents ( components) ) ) if components. contains( expected_component)
213
+ )
214
+ }
215
+
203
216
#[ tokio:: test]
204
217
async fn file_directory_update ( ) {
205
218
trace_init ( ) ;
@@ -209,10 +222,15 @@ mod tests {
209
222
let file_path = dir. join ( "vector.toml" ) ;
210
223
let watcher_conf = WatcherConfig :: RecommendedWatcher ;
211
224
let component_file_path = vec ! [ dir. join( "tls.cert" ) , dir. join( "tls.key" ) ] ;
225
+ let http_component = ComponentKey :: from ( "http" ) ;
226
+
212
227
let component_config =
213
- ComponentConfig :: new ( component_file_path, ComponentKey :: from ( "http" ) ) ;
228
+ ComponentConfig :: new ( component_file_path. clone ( ) , http_component . clone ( ) ) ;
214
229
std:: fs:: create_dir ( & dir) . unwrap ( ) ;
215
230
let mut file = File :: create ( & file_path) . unwrap ( ) ;
231
+ let mut component_files: Vec < std:: fs:: File > = component_file_path. iter ( ) . map ( |file| {
232
+ File :: create ( & file) . unwrap ( )
233
+ } ) . collect ( ) ;
216
234
217
235
let ( signal_tx, signal_rx) = broadcast:: channel ( 128 ) ;
218
236
spawn_thread (
@@ -224,7 +242,18 @@ mod tests {
224
242
)
225
243
. unwrap ( ) ;
226
244
227
- if !test ( & mut file, delay * 5 , signal_rx) . await {
245
+ let signal_rx2 = signal_rx. resubscribe ( ) ;
246
+ let signal_rx3 = signal_rx. resubscribe ( ) ;
247
+
248
+ if !test_component_reload ( & mut component_files[ 0 ] , & http_component, delay * 5 , signal_rx) . await {
249
+ panic ! ( "Test timed out" ) ;
250
+ }
251
+
252
+ if !test_component_reload ( & mut component_files[ 1 ] , & http_component, delay * 5 , signal_rx2) . await {
253
+ panic ! ( "Test timed out" ) ;
254
+ }
255
+
256
+ if !test ( & mut file, delay * 5 , signal_rx3) . await {
228
257
panic ! ( "Test timed out" ) ;
229
258
}
230
259
}
0 commit comments