@@ -7,22 +7,42 @@ mkdir -p target
77rm -rf ./target/trace-context
88git clone https://github.com/w3c/trace-context ./target/trace-context
99cd ./target/trace-context && git checkout $TRACECONTEXT_GIT_TAG && cd -
10- # start example opentelemetry service, which propagates trace-context by
10+ # start example opentelemetry service, which propagates trace-context by
1111# default.
1212python ./tests/w3c_tracecontext_validation_server.py 1>&2 &
1313EXAMPLE_SERVER_PID=$!
14- # give the app server a little time to start up. Not adding some sort
15- # of delay would cause many of the tracecontext tests to fail being
16- # unable to connect.
17- sleep 1
18- onshutdown ()
14+ onshutdown ()
1915{
2016 # send a sigint, to ensure
2117 # it is caught as a KeyboardInterrupt in the
2218 # example service.
2319 kill $EXAMPLE_SERVER_PID
2420}
2521trap onshutdown EXIT
22+ # Wait for the example server to accept connections on 127.0.0.1:5000
23+ # before running the W3C tracecontext tests. A fixed `sleep` raced the
24+ # Flask startup on slow CI runners and produced intermittent connection
25+ # errors (see issue #5104).
26+ wait_for_server () {
27+ host=127.0.0.1
28+ port=5000
29+ deadline=$(( $(date +% s) + 30 ))
30+ while [ " $( date +%s) " -lt " $deadline " ]; do
31+ # Bail out early if the server process died.
32+ if ! kill -0 " $EXAMPLE_SERVER_PID " 2> /dev/null; then
33+ echo " tracecontext example server exited before becoming ready" >&2
34+ return 1
35+ fi
36+ # Use python so we don't depend on extra tools (nc, curl, etc.).
37+ if python -c " import socket,sys; s=socket.socket(); s.settimeout(1); sys.exit(0 if s.connect_ex(('$host ', $port )) == 0 else 1)" 2> /dev/null; then
38+ return 0
39+ fi
40+ sleep 0.5
41+ done
42+ echo " tracecontext example server did not become ready within 30s" >&2
43+ return 1
44+ }
45+ wait_for_server
2646cd ./target/trace-context/test
2747
2848# The disabled test is not compatible with an optional part of the W3C
0 commit comments