Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ public ClientHttpResponse validateRequest(ClientHttpRequest request) throws IOEx
if (requests.isEmpty()) {
afterExpectationsDeclared();
}
ClientHttpResponse response = validateRequestInternal(request);
requests.add(request);
return response;
try {
return validateRequestInternal(request);
}
finally {
requests.add(request);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.test.web.client;

import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;

Expand All @@ -30,6 +31,7 @@
import static org.junit.Assert.assertEquals;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.test.util.AssertionErrors.fail;
import static org.springframework.test.web.client.ExpectedCount.max;
import static org.springframework.test.web.client.ExpectedCount.min;
import static org.springframework.test.web.client.ExpectedCount.once;
Expand Down Expand Up @@ -184,6 +186,23 @@ public void repeatedRequestsInSequentialOrder() throws Exception {
this.manager.validateRequest(createRequest(GET, "/bar"));
}

@Test // SPR-16132
public void sequentialRequestsWithFirstFailing() throws Exception {
this.manager.expectRequest(once(), requestTo("/foo")).andExpect(method(GET))
.andRespond(request -> { throw new SocketException("pseudo network error"); });
this.manager.expectRequest(once(), requestTo("/handle-error")).andExpect(method(POST)).andRespond(withSuccess());

try {
this.manager.validateRequest(createRequest(GET, "/foo"));
fail("expected exception");
}
catch (SocketException e) {
//expected
}
this.manager.validateRequest(createRequest(POST, "/handle-error"));
this.manager.verify();
}


private ClientHttpRequest createRequest(HttpMethod method, String url) {
try {
Expand Down