Skip to content

Commit 0b0ffa0

Browse files
committed
Repair Flaky Tests
- MockWebServer seems to start failing to respond to connections at a certain frequency of requests. This commit builds in a small delay of 1 millisecond to address this. Closes gh-15395
1 parent e0be46e commit 0b0ffa0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

saml2/saml2-service-provider/src/test/java/org/springframework/security/saml2/provider/service/registration/OpenSamlAssertingPartyMetadataRepositoryTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Collection;
2525
import java.util.List;
2626
import java.util.Set;
27+
import java.util.concurrent.TimeUnit;
2728
import java.util.stream.Collectors;
2829

2930
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
@@ -89,14 +90,14 @@ public void setup() throws Exception {
8990
@Test
9091
public void withMetadataUrlLocationWhenResolvableThenFindByEntityIdReturns() throws Exception {
9192
try (MockWebServer server = new MockWebServer()) {
92-
server.setDispatcher(new AlwaysDispatch(new MockResponse().setBody(this.metadata).setResponseCode(200)));
93+
server.setDispatcher(new AlwaysDispatch(this.metadata));
9394
AssertingPartyMetadataRepository parties = OpenSamlAssertingPartyMetadataRepository
94-
.withTrustedMetadataLocation(server.url("/").toString())
95-
.build();
95+
.withTrustedMetadataLocation(server.url("/").toString())
96+
.build();
9697
AssertingPartyMetadata party = parties.findByEntityId("https://idp.example.com/idp/shibboleth");
9798
assertThat(party.getEntityId()).isEqualTo("https://idp.example.com/idp/shibboleth");
9899
assertThat(party.getSingleSignOnServiceLocation())
99-
.isEqualTo("https://idp.example.com/idp/profile/SAML2/POST/SSO");
100+
.isEqualTo("https://idp.example.com/idp/profile/SAML2/POST/SSO");
100101
assertThat(party.getSingleSignOnServiceBinding()).isEqualTo(Saml2MessageBinding.POST);
101102
assertThat(party.getVerificationX509Credentials()).hasSize(1);
102103
assertThat(party.getEncryptionX509Credentials()).hasSize(1);
@@ -106,8 +107,7 @@ public void withMetadataUrlLocationWhenResolvableThenFindByEntityIdReturns() thr
106107
@Test
107108
public void withMetadataUrlLocationnWhenResolvableThenIteratorReturns() throws Exception {
108109
try (MockWebServer server = new MockWebServer()) {
109-
server.setDispatcher(
110-
new AlwaysDispatch(new MockResponse().setBody(this.entitiesDescriptor).setResponseCode(200)));
110+
server.setDispatcher(new AlwaysDispatch(this.entitiesDescriptor));
111111
List<AssertingPartyMetadata> parties = new ArrayList<>();
112112
OpenSamlAssertingPartyMetadataRepository.withTrustedMetadataLocation(server.url("/").toString())
113113
.build()
@@ -360,7 +360,7 @@ private static final class AlwaysDispatch extends Dispatcher {
360360
private final MockResponse response;
361361

362362
private AlwaysDispatch(String body) {
363-
this.response = new MockResponse().setBody(body).setResponseCode(200);
363+
this.response = new MockResponse().setBody(body).setResponseCode(200).setBodyDelay(1, TimeUnit.MILLISECONDS);
364364
}
365365

366366
private AlwaysDispatch(MockResponse response) {

0 commit comments

Comments
 (0)