Skip to content

Commit da2d877

Browse files
committed
refine testing
1 parent b8d0303 commit da2d877

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

src/test/java/com/uid2/operator/OperatorShutdownHandlerTest.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,14 @@ void saltsLogErrorAtInterval(VertxTestContext testContext) {
171171

172172
@Test
173173
void storeRefreshRecordsSuccessTimestamp(VertxTestContext testContext) {
174-
// Record successful refresh at baseTime
175174
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
176175

177-
// Advance time by 11 hours (still under threshold) - should NOT trigger shutdown
178176
when(clock.instant()).thenReturn(baseTime.plus(11, ChronoUnit.HOURS));
179177
assertDoesNotThrow(() -> {
180178
this.operatorShutdownHandler.checkStoreRefreshStaleness();
181179
});
182180
verify(shutdownService, never()).Shutdown(anyInt());
183181

184-
// Now advance time to 13 hours from original success - SHOULD trigger shutdown
185182
when(clock.instant()).thenReturn(baseTime.plus(13, ChronoUnit.HOURS));
186183
try {
187184
this.operatorShutdownHandler.checkStoreRefreshStaleness();
@@ -193,22 +190,17 @@ void storeRefreshRecordsSuccessTimestamp(VertxTestContext testContext) {
193190

194191
@Test
195192
void storeRefreshFailureDoesNotResetTimestamp(VertxTestContext testContext) {
196-
// Record successful refresh at baseTime
197193
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
198194

199-
// Advance time by 2 hours
200195
when(clock.instant()).thenReturn(baseTime.plus(2, ChronoUnit.HOURS));
201196

202-
// Record multiple failures - these should NOT reset the timestamp
203197
this.operatorShutdownHandler.handleStoreRefresh("test_store", false);
204198
this.operatorShutdownHandler.handleStoreRefresh("test_store", false);
205199
this.operatorShutdownHandler.handleStoreRefresh("test_store", false);
206200

207-
// Advance time to 13 hours from ORIGINAL success (not from failures)
208-
// This proves failures didn't reset the timestamp
201+
209202
when(clock.instant()).thenReturn(baseTime.plus(13, ChronoUnit.HOURS));
210203

211-
// Should trigger shutdown based on original success timestamp
212204
try {
213205
this.operatorShutdownHandler.checkStoreRefreshStaleness();
214206
} catch (RuntimeException e) {
@@ -223,13 +215,10 @@ void storeRefreshStaleShutdown(VertxTestContext testContext) {
223215
logWatcher.start();
224216
((Logger) LoggerFactory.getLogger(OperatorShutdownHandler.class)).addAppender(logWatcher);
225217

226-
// Initial successful refresh at baseTime
227218
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
228219

229-
// Move time forward by 12 hours + 1 second from baseTime
230220
when(clock.instant()).thenReturn(baseTime.plus(12, ChronoUnit.HOURS).plusSeconds(1));
231221

232-
// Check staleness - should trigger shutdown
233222
try {
234223
this.operatorShutdownHandler.checkStoreRefreshStaleness();
235224
} catch (RuntimeException e) {
@@ -243,19 +232,14 @@ void storeRefreshStaleShutdown(VertxTestContext testContext) {
243232

244233
@Test
245234
void storeRefreshRecoverBeforeStale(VertxTestContext testContext) {
246-
// Initial successful refresh at baseTime
247235
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
248236

249-
// Move time forward by 11 hours from baseTime
250237
when(clock.instant()).thenReturn(baseTime.plus(11, ChronoUnit.HOURS));
251238

252-
// Another successful refresh before timeout (at baseTime + 11 hours)
253239
this.operatorShutdownHandler.handleStoreRefresh("test_store", true);
254240

255-
// Move time forward another 12 hours from original time (but only 1 hour from last refresh at baseTime + 11h)
256241
when(clock.instant()).thenReturn(baseTime.plus(12, ChronoUnit.HOURS));
257242

258-
// Check staleness - should NOT trigger shutdown (only 1 hour since last refresh)
259243
assertDoesNotThrow(() -> {
260244
this.operatorShutdownHandler.checkStoreRefreshStaleness();
261245
});
@@ -269,22 +253,18 @@ void multipleStoresOneStaleTriggers(VertxTestContext testContext) {
269253
logWatcher.start();
270254
((Logger) LoggerFactory.getLogger(OperatorShutdownHandler.class)).addAppender(logWatcher);
271255

272-
// Multiple stores succeed at baseTime
256+
273257
this.operatorShutdownHandler.handleStoreRefresh("store1", true);
274258
this.operatorShutdownHandler.handleStoreRefresh("store2", true);
275259
this.operatorShutdownHandler.handleStoreRefresh("store3", true);
276260

277-
// Move time forward by 6 hours from baseTime
278261
when(clock.instant()).thenReturn(baseTime.plus(6, ChronoUnit.HOURS));
279262

280-
// Store1 and Store2 refresh successfully at baseTime+6h, but Store3 doesn't
281263
this.operatorShutdownHandler.handleStoreRefresh("store1", true);
282264
this.operatorShutdownHandler.handleStoreRefresh("store2", true);
283265

284-
// Move time forward 12 hours from baseTime (store3 hasn't refreshed for 12 hours)
285266
when(clock.instant()).thenReturn(baseTime.plus(12, ChronoUnit.HOURS).plusSeconds(1));
286267

287-
// Check staleness - should trigger shutdown for store3
288268
try {
289269
this.operatorShutdownHandler.checkStoreRefreshStaleness();
290270
} catch (RuntimeException e) {
@@ -298,8 +278,7 @@ void multipleStoresOneStaleTriggers(VertxTestContext testContext) {
298278

299279
@Test
300280
void noShutdownWhenStoreNeverInitialized(VertxTestContext testContext) {
301-
// Don't register any successful refresh for a store
302-
// Just check staleness immediately
281+
303282
assertDoesNotThrow(() -> {
304283
this.operatorShutdownHandler.checkStoreRefreshStaleness();
305284
});
@@ -325,11 +304,9 @@ void periodicCheckOnlyStartsOnce(Vertx vertx, VertxTestContext testContext) {
325304
logWatcher.start();
326305
((Logger) LoggerFactory.getLogger(OperatorShutdownHandler.class)).addAppender(logWatcher);
327306

328-
// Start the periodic check twice
329307
this.operatorShutdownHandler.startPeriodicStaleCheck(vertx);
330308
this.operatorShutdownHandler.startPeriodicStaleCheck(vertx);
331309

332-
// Should log a warning
333310
Assertions.assertTrue(logWatcher.list.stream().anyMatch(log ->
334311
log.getFormattedMessage().contains("already started")));
335312
testContext.completeNow();

0 commit comments

Comments
 (0)