-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(csi): prevent race condition in ci tests step (#426)
* fix(csi): prevent race condition in ci tests step Signed-off-by: Alessio Pragliola <[email protected]> * chore(csi): reword repeat_cmd_until fail msg Signed-off-by: Alessio Pragliola <[email protected]> * refactor(csi): move wait_for_port in test_utils Signed-off-by: Alessio Pragliola <[email protected]> --------- Signed-off-by: Alessio Pragliola <[email protected]>
- Loading branch information
1 parent
89fdaff
commit 3110d1b
Showing
2 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |