HTTP is a synchronous protocol* so active polling is not an option. You need to wait until client receives response or request times out. There are two ways to constrain synchronous behaviour with timeout.
One is to set a timeout for receiving a response. REST-Assured uses Apache HTTP Client for which you can set http.socket.timeout
and http.connection.timeout
. See answers for Apache HttpClient timeout and Apache HTTP Client documentation.
Another solution is to set a certain timeout for a block of your test code:
new TimeLimitedCodeBlock(5, TimeUnit.MINUTES) {
@Override
public void codeBlock() {
framework.createNewData();//Takes some time.
}
}.run();
TimeLimitedCodeBlock
is described in answers to Java: set timeout on a certain block of code?.
*Synchronous communication
In program-to-program communication, synchronous communication
requires that each end of an exchange of communication respond in turn
without initiating a new communication. A typical activity that might
use a synchronous protocol would be a transmission of files from one
point to another. As each transmission is received, a response is
returned indicating success or the need to resend. Each successive
transmission of data requires a response to the previous transmission
before a new one can be initiated.
EDIT
Active polling is not an option, because waiting for HTTP Response is synchronous: it blocks the current thread until response is received. TimeLimitedCodeBlock
class I mentioned waits for HTTP Response in a separate thread. The separate thread terminates when HTTP Response is received or time out passes. Instead of actively checking (polling) if a separate thread has received HTTP response, TimeLimitedCodeBlock
is waiting for a separate thread to terminate.