Skip to content

Commit 6452ef6

Browse files
committed
Fix testing
1 parent 14ace20 commit 6452ef6

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/config/watcher.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,19 @@ mod tests {
200200
)
201201
}
202202

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+
203216
#[tokio::test]
204217
async fn file_directory_update() {
205218
trace_init();
@@ -209,10 +222,15 @@ mod tests {
209222
let file_path = dir.join("vector.toml");
210223
let watcher_conf = WatcherConfig::RecommendedWatcher;
211224
let component_file_path = vec![dir.join("tls.cert"), dir.join("tls.key")];
225+
let http_component = ComponentKey::from("http");
226+
212227
let component_config =
213-
ComponentConfig::new(component_file_path, ComponentKey::from("http"));
228+
ComponentConfig::new(component_file_path.clone(), http_component.clone());
214229
std::fs::create_dir(&dir).unwrap();
215230
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();
216234

217235
let (signal_tx, signal_rx) = broadcast::channel(128);
218236
spawn_thread(
@@ -224,7 +242,18 @@ mod tests {
224242
)
225243
.unwrap();
226244

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 {
228257
panic!("Test timed out");
229258
}
230259
}

0 commit comments

Comments
 (0)