Best practice to run a process in the background and wait until it is ready

System:

  • Backend Application (RESTful HTTP API) written in Java (Play Framework 2.3.x)
  • Frontend app (GUI using API) written in Javascript (angular with grunt for construction)
  • Travis CI is used for continuous integration

Problem:

I want to start / run a backend application and after running it successfully, I want to test it with a protractor (via grunt tasks).

But launching the backend application won't continue because it is not a termination process (server is running -> not terminated)

Enabling the server as a base process by adding &

may fix the problem, but then there is no guarantee that the server has started in the meantime.

Some tips on the internet say:

Add sleep (x) and run the test after that

But how much x?

Is there any other way to do this, instead of guessing (or measuring) the server startup time and sleeping after the server starts as a background process?

Edit: The result of starting the server (e.g. to periodically compare the background task output) is the following:

$ activator run
[info] Loading project definition from ...
[info] Set current project to ... (in build file:...)

--- (Running the application, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

      

+3


source to share


1 answer


You can do better than guessing or estimating how long to sleep before testing with a simple external test to see if the server is up, for example



while ! curl -s 0:0:0:0:0:0:0:0:9000 >/dev/null; do
    sleep 1
done

# now start real tests
...

      

0


source







All Articles