460905 - Make sure TimeoutCompleteListener is cancelled if the request cannot be sent.

This commit is contained in:
Simone Bordet 2015-02-26 12:25:42 +01:00
parent d5a6ad2345
commit 008b03ac78
2 changed files with 17 additions and 8 deletions

View File

@ -683,6 +683,7 @@ public class HttpRequest implements Request
// can't even start sending the request. // can't even start sending the request.
if (timeoutListener != null) if (timeoutListener != null)
timeoutListener.cancel(); timeoutListener.cancel();
throw x;
} }
} }

View File

@ -434,15 +434,23 @@ public class HttpClientTimeoutTest extends AbstractHttpClientServerTest
start(new EmptyServerHandler()); start(new EmptyServerHandler());
long timeout = 1000; long timeout = 1000;
Request request = client.newRequest("bad_scheme://localhost:" + connector.getLocalPort()); Request request = client.newRequest("badscheme://localhost:" + connector.getLocalPort());
request.timeout(timeout, TimeUnit.MILLISECONDS)
.send(new Response.CompleteListener() try
{ {
@Override request.timeout(timeout, TimeUnit.MILLISECONDS)
public void onComplete(Result result) .send(new Response.CompleteListener()
{ {
} @Override
}); public void onComplete(Result result)
{
}
});
Assert.fail();
}
catch (Exception expected)
{
}
Thread.sleep(2 * timeout); Thread.sleep(2 * timeout);