2
2
3
3
import static com .github .kagkarlsson .jdbc .PreparedStatementSetter .NOOP ;
4
4
import static org .hamcrest .MatcherAssert .assertThat ;
5
- import static org .hamcrest .Matchers .is ;
5
+ import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
6
6
import static org .junit .jupiter .api .Assertions .assertTrue ;
7
7
8
8
import com .github .kagkarlsson .jdbc .JdbcRunner ;
21
21
import java .time .Instant ;
22
22
import java .util .List ;
23
23
import org .hamcrest .collection .IsCollectionWithSize ;
24
- import org .junit .jupiter .api .Test ;
24
+ import org .junit .jupiter .api .RepeatedTest ;
25
25
import org .junit .jupiter .api .extension .RegisterExtension ;
26
26
import org .slf4j .Logger ;
27
27
import org .slf4j .LoggerFactory ;
@@ -34,7 +34,7 @@ public class DetectStaleHeartbeatTest {
34
34
35
35
@ RegisterExtension public StopSchedulerExtension stopScheduler = new StopSchedulerExtension ();
36
36
37
- @ Test
37
+ @ RepeatedTest ( 10 ) // FIXLATER: remove when test is stable
38
38
public void test_dead_execution () throws InterruptedException {
39
39
PausingHandler <Void > handler = new PausingHandler <>();
40
40
@@ -44,7 +44,7 @@ public void test_dead_execution() throws InterruptedException {
44
44
.execute (handler );
45
45
46
46
TestableRegistry .Condition ranUpdateHeartbeats =
47
- TestableRegistry .Conditions .ranUpdateHeartbeats (2 );
47
+ TestableRegistry .Conditions .ranUpdateHeartbeats (3 );
48
48
TestableRegistry .Condition ranExecuteDue = TestableRegistry .Conditions .ranExecuteDue (1 );
49
49
50
50
TestableRegistry registry =
@@ -54,6 +54,7 @@ public void test_dead_execution() throws InterruptedException {
54
54
Scheduler .create (postgres .getDataSource (), customTask )
55
55
.pollingInterval (Duration .ofMillis (30 ))
56
56
.heartbeatInterval (Duration .ofMillis (30 ))
57
+ .missedHeartbeatsLimit (10 )
57
58
.schedulerName (new SchedulerName .Fixed ("test" ))
58
59
.statsRegistry (registry )
59
60
.build ();
@@ -74,6 +75,7 @@ public void test_dead_execution() throws InterruptedException {
74
75
assertThat (failing , IsCollectionWithSize .hasSize (1 ));
75
76
HeartbeatState state = failing .get (0 ).getHeartbeatState ();
76
77
assertTrue (state .hasStaleHeartbeat ());
77
- assertThat (state .getFailedHeartbeats (), is (2 ));
78
+ // update-heartbeats may have run once before this execution was picked, hence >= 2 and not == 3
79
+ assertThat (state .getFailedHeartbeats (), greaterThanOrEqualTo (2 ));
78
80
}
79
81
}
0 commit comments