Try to stabilize SampleSessionWebFluxApplicationTests

userDefinedMappingsSecureByDefault in
SampleSessionWebFluxApplicationTests may fail with an NPE if the
session times out before the initial response is sent due to the absence
of a SESSION cookie in the response. The test uses a short session
timeout (2 seconds) and we've seen the problem occur on CI when,
presumably, a noisy neighbour has caused some CPU starvation.

This commit increases the timeout to 5 seconds to reduce the chance of
a short period of CPU starvation causing the test to fail.

Closes gh-25572
This commit is contained in:
Andy Wilkinson 2021-03-10 13:56:23 +00:00
parent f38e863fbc
commit 4d3d56abfe

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Vedran Pavic * @author Vedran Pavic
*/ */
@SpringBootTest(properties = "server.servlet.session.timeout:2", @SpringBootTest(properties = "server.servlet.session.timeout:5",
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class SampleSessionWebFluxApplicationTests { class SampleSessionWebFluxApplicationTests {
@ -57,7 +57,7 @@ class SampleSessionWebFluxApplicationTests {
response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30));
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK); assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId); assertThat(response.bodyToMono(String.class).block(Duration.ofSeconds(30))).isEqualTo(sessionId);
Thread.sleep(2000); Thread.sleep(5000);
response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30)); response = webClient.get().cookie("SESSION", sessionCookie.getValue()).exchange().block(Duration.ofSeconds(30));
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }