I am working on an Ant target for running tests, and I need to have an app server up and running before the tests start. I’m using the waitFor task to ping a URL until it gets a response. This works, except that I need to not only make sure the URL is simply accessible, but also check that a particular status string is present. This second requirement is simple on its own, with a get or telnet task, followed by a substring search. But the ‘waitfor’ task doesn’t accept any nested elements other than standard Ant conditions, or things they can wrap (things that return booleans). I have tried loading the URL as a resource prior to running the ‘waitfor’ task with a resourceconatins condition, but that caches the response, and doesn’t refresh from the server.
Is there a way to force the URL to be loaded on each loop? Or some other way to achieve this?
Here’s what I want to achieve in pseudo-code:
<waitfor>
<and>
<!-- make sure the URL is accessible at all -->
<http url="theurl.jsp"/>
<!-- load the URL as a resource and make sure it contains a substring -->
<!-- moving the "url" task before the waitfor works if all conditions are met the first time through, but does not refresh the URL if it has to loop over again. having it inside like this, fails because waitfor/and don't support nexted "url" tasks -->
<url id="url.resource" url="url.jsp"/>
<resourcecontains refid="url.resource" substring="status"/>
</and>
<!-- else, keep on trying until timeout -->
</waitfor>
<!-- continue on to the tests to be run -->
Usage:
Code below allows for this: