@@ -71,7 +71,7 @@ def __init__(self, name, auth, sleep, schemaformat, classfiles):
7171
7272
7373
74- SLEEP = 120
74+ SLEEP = 180
7575YAML = "yaml"
7676JSON = "json"
7777
@@ -214,12 +214,40 @@ def writeScript(basedir, code, port, tool, sut):
214214def dockerId (port ):
215215 return "id" + str (port )
216216
217+ def getWaitForSutFunction ():
218+ s = "wait_for_sut() {\n "
219+ s += " local host_port=\" $1\" \n "
220+ s += " local max_wait=\" ${2:-600}\" \n "
221+ s += " local interval=10\n "
222+ s += " local elapsed=0\n "
223+ s += "\n "
224+ s += " echo \" Waiting for SUT on port $host_port (max: ${max_wait}s)...\" \n "
225+ s += "\n "
226+ s += " while [ $elapsed -lt $max_wait ]; do\n "
227+ s += " sleep $interval\n "
228+ s += " elapsed=$((elapsed + interval))\n "
229+ s += "\n "
230+ s += " http_code=$(curl -s -o /dev/null -w \" %{http_code}\" --connect-timeout 5 --max-time 10 \" http://localhost:$host_port\" 2>/dev/null)\n "
231+ s += " if [ -n \" $http_code\" ] && [ \" $http_code\" -ge 100 ] 2>/dev/null; then\n "
232+ s += " echo \" SUT is ready after ${elapsed}s (HTTP $http_code on port $host_port)\" \n "
233+ s += " return 0\n "
234+ s += " fi\n "
235+ s += "\n "
236+ s += " echo \" Still waiting... ${elapsed}s / ${max_wait}s (port $host_port not responding)\" \n "
237+ s += " done\n "
238+ s += "\n "
239+ s += " echo \" WARNING: Timeout after ${max_wait}s, proceeding anyway...\" \n "
240+ s += "}\n \n "
241+ return s
242+
217243def getScriptHead (port ,tool ,sut , exec_dir ):
218244 s = ""
219245 s += "#!/bin/bash \n \n "
220246 s += "SUT=\" " + WFD_DIR + "/dockerfiles/" + sut .name + ".yaml\" \n "
221247 s += "\n "
222248
249+ s += getWaitForSutFunction ()
250+
223251 # These environment variables are read inside Docker Compose
224252 # Must be on same line of docker, so that why using \.
225253 # Note: there must be NOTHING after the \, not even empty space " "...
@@ -234,8 +262,8 @@ def getScriptHead(port,tool,sut, exec_dir):
234262 # Start SUT with Docker Compose
235263 s += "docker-compose --project-name " + dockerId (port )+ " -f $SUT up --build --force-recreate " + getRedirectLog (getLogFile ("sut" ,tool ,sut .name ,port )) + " & \n \n "
236264
237- # No easy way to check if all is up and running, so wait for enough time before fuzzing
238- s += "sleep " + str (sut .sleep ) + "\n \n "
265+ # Wait until HTTP endpoint on target port responds (or timeout)
266+ s += "wait_for_sut " + str (port ) + " " + str ( sut .sleep ) + "\n \n "
239267
240268 return s
241269
0 commit comments