From a9b329af557cad0a9bec1657e2e79f820de4bfdc Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 18 Jul 2024 10:57:09 -0400 Subject: [PATCH] GH-456: Fix `EnableRetryWithBackoffTests.randomExponential()` for random Fixes: #456 The random logic in the `ExponentialRandomBackOffPolicy` may end up with close to the `1`. And after casting to `long` we got the same `1000` * Fix test respectively to include that possibility. --- .../retry/annotation/EnableRetryWithBackoffTests.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java index e10458db..25b2669a 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryWithBackoffTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ /** * @author Dave Syer + * @author Artem Bilan * */ public class EnableRetryWithBackoffTests { @@ -74,9 +75,10 @@ public void randomExponential() { assertThat(service.getCount()).isEqualTo(3); List periods = context.getBean(PeriodSleeper.class).getPeriods(); assertThat(context.getBean(PeriodSleeper.class).getPeriods().toString()).isNotEqualTo("[1000, 1100]"); - assertThat(periods.get(0) > 1000).describedAs("Wrong periods: %s" + periods.toString()).isTrue(); - assertThat(periods.get(1) > 1100 && periods.get(1) < 1210).describedAs("Wrong periods: %s" + periods.toString()) - .isTrue(); + assertThat(periods.get(0)).describedAs("Wrong periods: %s" + periods).isGreaterThanOrEqualTo(1000); + assertThat(periods.get(1)).describedAs("Wrong periods: %s" + periods) + .isGreaterThanOrEqualTo(1100) + .isLessThanOrEqualTo(1210); context.close(); }