GNU parallel: Running tests against a service - Fail early

Viewed 32

I am using parallel to parallelize automatic tests against a service as part of a build pipeline. Essentially, my current approach is to use the following. In the end, what should happen:

  • As soon as both tests are successfully -> success
  • As soon as any one of the job fails -> terminate all and return error

However, it currently happens that of course the service runs indefinitely (unless cancelled), so thats why below I put success=2. If a test fails, however, this will never trigger, and thus I had to add a --timeout 120. However, this only leads to the workaround that after a test fails, I have to wait 2 more minutes to received that info.

parallel --halt now,success=2 -j3 ::: start_service.py test1.py test2.py

EDIT: It turns out that parallel per default is installed with 2016xx verison using apt-get. After installing from source on debian buster; I can at least start using the following:

parallel --halt now,done=2 -j3 ::: start_service.py test1.py test2.py

However, this returns a non-zero exist status even if the two tests are successful.

1 Answers

You are thinking the right thing, but focusing on the wrong conclusion.

Do not focus on success but on failure:

start_service.py &
# wait until service is ready then run:
parallel --halt now,fail=1 -j0 ::: test1.py test2.py
# stop service
stop_service.py
Related