Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(csi): prevent race condition in ci tests step #426

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions csi/test/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ set -o xtrace
# This test assumes there is a Kubernetes environment up and running.
# It could be either a remote one or a local one (e.g., using KinD or minikube).

# Function to check if the port is ready
wait_for_port() {
local port=$1
while ! nc -z localhost $port; do
sleep 0.1
done
}

DIR="$(dirname "$0")"

source ./${DIR}/test_utils.sh

KUBECTL=${KUBECTL:-"kubectl"}

# You can provide a local version of the model registry storage initializer
Expand Down Expand Up @@ -145,7 +139,7 @@ spec:
EOF

# wait for pod predictor to be initialized
sleep 2
repeat_cmd_until "kubectl get pod -n $KSERVE_TEST_NAMESPACE --selector='component=predictor' | wc -l" "-gt 0" 60
predictor=$(kubectl get pod -n $KSERVE_TEST_NAMESPACE --selector="component=predictor" --output jsonpath='{.items[0].metadata.name}')
kubectl wait --for=condition=Ready pod/$predictor -n $KSERVE_TEST_NAMESPACE --timeout=5m

Expand Down
38 changes: 38 additions & 0 deletions csi/test/test_utils.sh
Al-Pragliola marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -e
set -o xtrace

# Function to check if the port is ready
wait_for_port() {
local port=$1
while ! nc -z localhost $port; do
sleep 0.1
done
}

repeat_cmd_until() {
local cmd=$1
local condition=$2
local max_wait_secs=$3
local interval_secs=2
local start_time=$(date +%s)
local output

while true; do

current_time=$(date +%s)
if (( (current_time - start_time) > max_wait_secs )); then
echo "Waited for expression "$1" to satisfy condition "$2" for $max_wait_secs seconds without luck. Returning with error."
return 1
fi

output=$(eval $cmd)

if [ $output $condition ]; then
break
else
sleep $interval_secs
fi
done
}