This is an automated email from the ASF dual-hosted git repository.

janhoy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 86f727a  Wait for the port-forward instead of sleeping in the smoke 
test (#861)
86f727a is described below

commit 86f727aed41bce10bddea097134cf73d83569f42
Author: Jan Høydahl <[email protected]>
AuthorDate: Sun Oct 25 16:16:16 2026 +0100

    Wait for the port-forward instead of sleeping in the smoke test (#861)
---
 hack/release/smoke_test/test_cluster.sh | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/hack/release/smoke_test/test_cluster.sh 
b/hack/release/smoke_test/test_cluster.sh
index 75c0b30..2ee3e43 100755
--- a/hack/release/smoke_test/test_cluster.sh
+++ b/hack/release/smoke_test/test_cluster.sh
@@ -104,6 +104,35 @@ function remove_solr_helm_repo() {
   fi
 }
 
+# Wait until a backgrounded 'kubectl port-forward' is accepting connections.
+#
+# A fixed sleep races with the port-forward: on a loaded machine the forward 
can print
+# "Forwarding from ..." only after the first request has already been refused, 
and with
+# 'set -e' that aborts the whole smoke test. Any HTTP response means the 
forward is up,
+# so a non-zero curl exit (7 for a refused connection) is what we retry on.
+function wait_for_port_forward() {
+  local port="$1"
+  local timeout=60
+  local deadline=$((SECONDS + timeout))
+  local probe
+  while (( SECONDS < deadline )); do
+    # Bound each probe by the time actually left. A port that is listening but 
not yet
+    # proxying accepts the connection and then hangs, so a fixed --max-time 
per attempt
+    # would let an attempt count overrun the deadline several times over. 
Never pass 0,
+    # which curl reads as "no timeout at all".
+    probe=$((deadline - SECONDS))
+    if (( probe > 2 )); then
+      probe=2
+    fi
+    if curl --silent --max-time "${probe}" --output /dev/null 
"http://127.0.0.1:${port}/";; then
+      return 0
+    fi
+    sleep 1
+  done
+  echo "Timed out after ${timeout}s waiting for the port-forward on 
localhost:${port} to accept connections" >&2
+  return 1
+}
+
 # If LOCATION is not a URL, then get the absolute path
 if ! (echo "${LOCATION}" | grep "http"); then
   LOCATION=$(cd "${LOCATION}"; pwd)
@@ -208,7 +237,7 @@ grep -q "2              2       2            2" <(exec 
kubectl get solrcloud exa
 
 # Expose the common Solr service to localhost
 kubectl port-forward service/example-solrcloud-common 18983:80 || true &
-sleep 2
+wait_for_port_forward 18983
 
 printf "\nCheck the admin URL to make sure it works\n"
 curl --silent "http://localhost:18983/solr/admin/info/health"; | grep 
'"status":0' > /dev/null
@@ -318,7 +347,7 @@ grep -q "2              2       2            2" <(exec 
kubectl get solrcloud exa
 
 # Need a new port-forward, since the last one will have broken due to all pods 
restarting
 kubectl port-forward service/example-solrcloud-common 28983:80 || true &
-sleep 2
+wait_for_port_forward 28983
 
 printf "\nQuery the test collection, test for 0 docs\n\n"
 curl --silent "http://localhost:28983/solr/smoke-test/select"; | grep 
'\"numFound\":0' > /dev/null

Reply via email to