I am trying to setup a travis script where we run our application to make sure it starts up fine. If it does then we can pass the build. Testing catches errors on start up. However, it is an api server and if I run the binary and it is successful it will just run indefinitely.
I tried using the following:
timeout --preserve-status 20s <binary>
But this just returns the exit code of the binary which is 143 when killed from a timeout.
timeout 20s <binary>
This returns exit 127 when successful.
Is there a script I could use that runs the binary fails if the binary errors on startup and if sucessful starting up say after 20 seconds exits with 0 to pass the travis build?
In case you want to:
Return Exit code 0:
Return Exit code 1:
Then try this:
timeout 10m some_command || ( [[ $? -eq 124 ]] && \
echo "WARNING: Timeout reached, but that's OK" )
No need to use sleep
you can change your command in the following way to force the return code at 0
:
(timeout 20s <binary>; exit 0)
Example:
(timeout 2s '/bin/sleep' 100; exit 0) #subshell creation
echo $?
0
vs
timeout 2s '/bin/sleep' 100
echo $?
124
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With