Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(agent-harness): abort mock server on drop in e2e test

Steven Enamakelb93c3267f9e1
diff --git a/tests/agent_harness_e2e.rs b/tests/agent_harness_e2e.rs
index c152d96581..d9a59e0202 100644
--- a/tests/agent_harness_e2e.rs
+++ b/tests/agent_harness_e2e.rs
@@ -907,6 +907,27 @@ struct CaptureProxy {
port: u16,
}
+struct AbortOnDropMock {
+ join: Option<tokio::task::JoinHandle<Result<(), std::io::Error>>>,
+}
+
+impl AbortOnDropMock {
+ async fn shutdown_and_wait(mut self) {
+ if let Some(join) = self.join.take() {
+ join.abort();
+ let _ = join.await;
+ }
+ }
+}
+
+impl Drop for AbortOnDropMock {
+ fn drop(&mut self) {
+ if let Some(join) = &self.join {
+ join.abort();
+ }
+ }
+}
+
impl Drop for CaptureProxy {
fn drop(&mut self) {
let _ = self.child.kill();
@@ -1123,6 +1144,9 @@ async fn managed_host_requests_repeat_with_the_same_capture_identity_inner() {
}
None => serve_on_ephemeral(scripted_upstream_router()).await,
};
+ let mock_join = AbortOnDropMock {
+ join: Some(mock_join),
+ };
let mock_origin = format!("http://{actual_mock_addr}");
if let Some(endpoints) = endpoints.as_ref() {
assert_eq!(
@@ -1238,8 +1262,7 @@ async fn managed_host_requests_repeat_with_the_same_capture_identity_inner() {
);
}
drop(proxy);
- mock_join.abort();
- let _ = mock_join.await;
+ mock_join.shutdown_and_wait().await;
}
async fn bind_thread_action_dir(stack: &Stack, thread_id: &str, action_dir: &Path) {