From ac0e6960314d58614883186492682f8e803d43db Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Tue, 12 Jul 2022 06:17:47 +0100 Subject: [PATCH 1/2] examples: Improve waits/fix flakes Fix #22113 Signed-off-by: Ryan Northey --- examples/brotli/verify.sh | 5 ++++- examples/dynamic-config-cp/verify.sh | 11 ++++++----- examples/dynamic-config-fs/verify.sh | 1 + examples/ext_authz/verify.sh | 12 ++++++++++-- examples/verify-common.sh | 13 ++++++++++++- examples/wasm-cc/verify.sh | 7 ++++--- examples/zipkin-tracing/verify.sh | 8 ++++++-- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/examples/brotli/verify.sh b/examples/brotli/verify.sh index 18c37626846b1..7aca2b3e590a4 100755 --- a/examples/brotli/verify.sh +++ b/examples/brotli/verify.sh @@ -8,7 +8,10 @@ export PORT_STATS1="${BROTLI_PORT_PROXY:-10202}" # shellcheck source=examples/verify-common.sh . "$(dirname "${BASH_SOURCE[0]}")/../verify-common.sh" -sleep 5 +wait_for 10 bash -c "\ + responds_with_header \ + 'content-encoding: br' \ + https://localhost:${PORT_PROXY}/file.json -ki -H 'Accept-Encoding: br'" run_log "Test service: localhost:${PORT_PROXY}/file.json with compression" responds_with_header \ diff --git a/examples/dynamic-config-cp/verify.sh b/examples/dynamic-config-cp/verify.sh index c8f5303c8a9a1..57ae1ff0a908a 100755 --- a/examples/dynamic-config-cp/verify.sh +++ b/examples/dynamic-config-cp/verify.sh @@ -21,10 +21,8 @@ curl -s http://localhost:19000/config_dump \ run_log "Bring up go-control-plane" "$DOCKER_COMPOSE" up --build -d go-control-plane - wait_for 30 sh -c "${DOCKER_COMPOSE} ps go-control-plane | grep healthy | grep -v unhealthy" - -sleep 2 +wait_for 10 bash -c "responds_with 'Request served by service1' http://localhost:10000" run_log "Check for response from service1 backend" responds_with \ @@ -42,7 +40,10 @@ curl -s http://localhost:19000/config_dump \ run_log "Bring down the control plane" "$DOCKER_COMPOSE" stop go-control-plane -sleep 2 +wait_for 10 sh -c "\ + curl -s http://localhost:19000/config_dump \ + | jq -r '.configs[1].dynamic_active_clusters' \ + | grep '\"version_info\": \"1\"'" run_log "Check for continued response from service1 backend" responds_with \ @@ -63,7 +64,7 @@ sed -i'.bak' s/\"1\",/\"2\",/ resource.go run_log "Bring back up the control plane" "$DOCKER_COMPOSE" up --build -d go-control-plane -wait_for 30 sh -c "$DOCKER_COMPOSE ps go-control-plane | grep healthy | grep -v unhealthy" +wait_for 30 sh -c "${DOCKER_COMPOSE} ps go-control-plane | grep healthy | grep -v unhealthy" run_log "Check for response from service2 backend" responds_with \ diff --git a/examples/dynamic-config-fs/verify.sh b/examples/dynamic-config-fs/verify.sh index b9c55bb34e6f8..b57f54ef2e8bc 100755 --- a/examples/dynamic-config-fs/verify.sh +++ b/examples/dynamic-config-fs/verify.sh @@ -20,6 +20,7 @@ curl -s http://localhost:19000/config_dump \ run_log "Set upstream to service2" "$DOCKER_COMPOSE" exec -T proxy sed -i s/service1/service2/ /var/lib/envoy/cds.yaml +wait_for 10 bash -c "responds_with 'Request served by service2' http://localhost:10000" run_log "Check for response comes from service2 upstream" responds_with \ diff --git a/examples/ext_authz/verify.sh b/examples/ext_authz/verify.sh index 3097cb808d463..96ca5e61004c2 100755 --- a/examples/ext_authz/verify.sh +++ b/examples/ext_authz/verify.sh @@ -15,7 +15,12 @@ responds_with_header \ run_log "Restart front-envoy with FRONT_ENVOY_YAML=config/http-service.yaml" "$DOCKER_COMPOSE" down FRONT_ENVOY_YAML=config/http-service.yaml "$DOCKER_COMPOSE" up -d -sleep 10 + +wait_for 15 bash -c "\ + responds_with_header \ + 'HTTP/1.1 200 OK' \ + -H 'Authorization: Bearer token1' \ + http://localhost:${PORT_PROXY}/service" run_log "Test service responds with 403" responds_with_header \ @@ -31,7 +36,10 @@ responds_with_header \ run_log "Restart front-envoy with FRONT_ENVOY_YAML=config/opa-service/v3.yaml" "$DOCKER_COMPOSE" down FRONT_ENVOY_YAML=config/opa-service/v3.yaml "$DOCKER_COMPOSE" up -d -sleep 10 +wait_for 15 bash -c "\ + responds_with_header \ + 'HTTP/1.1 200 OK' \ + http://localhost:${PORT_PROXY}/service" run_log "Test OPA service responds with 200" responds_with_header \ diff --git a/examples/verify-common.sh b/examples/verify-common.sh index df70c9a95b98e..5b72350cb0d6f 100644 --- a/examples/verify-common.sh +++ b/examples/verify-common.sh @@ -150,7 +150,7 @@ wait_for () { local i=1 returns=1 seconds="$1" shift while ((i<=seconds)); do - if "$@"; then + if "${@}" &> /dev/null; then returns=0 break else @@ -158,6 +158,9 @@ wait_for () { ((i++)) fi done + if [[ "$returns" != 0 ]]; then + echo "Wait (${seconds}) failed: ${*}" >&2 + fi return "$returns" } @@ -171,3 +174,11 @@ fi if [[ -z "$MANUAL" ]]; then bring_up_example fi + + +# These allow the fun to be used in subshells, eg in `wait_for` +export -f responds_with +export -f responds_without +export -f responds_with_header +export -f responds_without_header +export -f _curl diff --git a/examples/wasm-cc/verify.sh b/examples/wasm-cc/verify.sh index c7bedbdfb3962..ef7d80ae1bcdd 100755 --- a/examples/wasm-cc/verify.sh +++ b/examples/wasm-cc/verify.sh @@ -34,9 +34,10 @@ sed -i'.bak' s/\\.\\/lib\\/envoy_filter_http_wasm_example.wasm/.\\/lib\\/envoy_f run_log "Bring the proxy back up" docker-compose up --build -d proxy - -run_log "Snooze for 5 while proxy starts" -sleep 5 +wait_for 10 bash -c "\ + responds_with \ + 'Hello, Wasm world' \ + http://localhost:8000" run_log "Test updated connection" responds_with \ diff --git a/examples/zipkin-tracing/verify.sh b/examples/zipkin-tracing/verify.sh index 3d8cfb4b146d7..024ce31a4373d 100755 --- a/examples/zipkin-tracing/verify.sh +++ b/examples/zipkin-tracing/verify.sh @@ -13,9 +13,13 @@ responds_with \ "Hello from behind Envoy (service 1)!" \ "http://localhost:${PORT_PROXY}/trace/1" -run_log "Test dashboard" # this could do with using the healthcheck and waiting -sleep 20 +wait_for 30 bash -c "\ + responds_with \ + '' \ + http://localhost:${PORT_ADMIN}/zipkin/" + +run_log "Test dashboard" responds_with \ "" \ "http://localhost:${PORT_ADMIN}/zipkin/" From 3d76d81eb2087c5d306f8069dde35892f53f3016 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Thu, 14 Jul 2022 15:38:06 +0100 Subject: [PATCH 2/2] comment-cleanup Signed-off-by: Ryan Northey --- examples/verify-common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/verify-common.sh b/examples/verify-common.sh index 5b72350cb0d6f..a679919bbbaad 100644 --- a/examples/verify-common.sh +++ b/examples/verify-common.sh @@ -176,7 +176,7 @@ if [[ -z "$MANUAL" ]]; then fi -# These allow the fun to be used in subshells, eg in `wait_for` +# These allow the functions to be used in subshells, e.g. in `wait_for` export -f responds_with export -f responds_without export -f responds_with_header