hubcio commented on code in PR #3729:
URL: https://github.com/apache/iggy/pull/3729#discussion_r3636828439


##########
core/integration/tests/connectors/fixtures/elasticsearch/container.rs:
##########
@@ -137,14 +195,308 @@ impl ElasticsearchContainer {
                 message: "No mapping for Elasticsearch port".to_string(),
             })?;
 
-        let base_url = format!("http://localhost:{mapped_port}";);
+        // Prefer IPv4 loopback: Docker publishes 0.0.0.0:HOST→9200. 
`localhost`
+        // can resolve to ::1 first on macOS and black-hole the 
elasticsearch-rs
+        // client while the fixture's reqwest client still looks healthy.
+        let base_url = format!("http://127.0.0.1:{mapped_port}";);
         info!("Elasticsearch container available at {base_url}");
 
-        Ok(Self {
+        let started = Self {
             container,
             base_url,
+        };
+        // ReuseDirective::Always can attach to a days-old container without
+        // re-running HttpWaitStrategy; verify cluster health on every setup.
+        started.wait_until_ready().await?;
+        started.sweep_stale_indices().await;
+        Ok(started)
+    }
+
+    async fn wait_until_ready(&self) -> Result<(), TestBinaryError> {
+        // Dedicated probe client: short timeout, no retry middleware. The 
shared
+        // create_http_client() (30s + 3 retries) turns one black-holed request
+        // into a multi-minute hang that looks like the test is stuck.
+        let client = reqwest::Client::builder()
+            .timeout(std::time::Duration::from_millis(
+                CLUSTER_READY_REQUEST_TIMEOUT_MS,
+            ))
+            .build()
+            .map_err(|error| TestBinaryError::FixtureSetup {
+                fixture_type: "ElasticsearchContainer".to_string(),
+                message: format!("Failed to build readiness HTTP client: 
{error}"),
+            })?;
+        // timeout=1s keeps ES from holding the request when the cluster is 
slow.
+        let health_url = format!(
+            "{}{ELASTICSEARCH_HEALTH_ENDPOINT}?timeout=1s",
+            self.base_url
+        );
+        let mut last_error = String::from("no attempts made");
+
+        for attempt in 1..=CLUSTER_READY_ATTEMPTS {
+            match client.get(&health_url).send().await {
+                Ok(response) if response.status().is_success() => {
+                    let body = response.text().await.unwrap_or_default();
+                    if body.contains("\"timed_out\":true") {

Review Comment:
   `?timeout=1s` without a `wait_for_*` param makes `/_cluster/health` return 
immediately with `timed_out: false`, so this check never fires - and any 200 
counts as ready even with cluster status red. 
`?wait_for_status=yellow&timeout=1s` makes both the timeout param and this 
check do real work (and then parsing the bool beats string-matching the body).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to