Skip to content

Commit 3d17e4c

Browse files
committed
Simulate payload expiration by clearing the database instead of using Thread.sleep
1 parent ead6e20 commit 3d17e4c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

captchaservice-backend/src/test/java/de/muenchen/captchaservice/controller/captcha/CaptchaControllerTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.testcontainers.junit.jupiter.Container;
3030
import org.testcontainers.utility.DockerImageName;
3131

32+
import java.time.Instant;
33+
3234
import static de.muenchen.captchaservice.TestConstants.SPRING_NO_SECURITY_PROFILE;
3335
import static de.muenchen.captchaservice.TestConstants.SPRING_TEST_PROFILE;
3436
import static org.hamcrest.Matchers.hasItem;
@@ -336,9 +338,8 @@ void testInvalidatedPayloadsGauge() {
336338
.andExpect(status().isOk())
337339
.andExpect(jsonPath("$.measurements[0].value", is(1.0)));
338340

339-
// Simulate the expiration of the payload
340-
Thread.sleep(captchaProperties.captchaTimeoutSeconds() * 1000);
341-
expiredDataService.deleteExpiredData();
341+
// Simulate the expiration of the payload by directly clearing the database
342+
databaseTestUtil.clearDatabase();
342343

343344
mockMvc.perform(get("/actuator/metrics/captcha.invalidated.payloads"))
344345
.andExpect(status().isOk())

0 commit comments

Comments
 (0)