Copilot commented on code in PR #4926:
URL: https://github.com/apache/bookkeeper/pull/4926#discussion_r4449566583


##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AuditorPeriodicCheckTest.java:
##########
@@ -898,6 +899,56 @@ public void testDelayBookieAuditOfReplicasCheck() throws 
Exception {
         auditor.close();
     }
 
+    /**
+     * Test that shutting down an auditor doesn't wait for the audit it delayed
+     * for a lost bookie.
+     */
+    @Test
+    public void testShutdownWithDelayedBookieAudit() throws Exception {
+        for (AuditorElector e : auditorElectors.values()) {
+            e.shutdown();
+        }
+        LedgerUnderreplicationManager urm = 
driver.getLedgerManagerFactory().newLedgerUnderreplicationManager();
+        urm.setLostBookieRecoveryDelay(Integer.MAX_VALUE);
+
+        ServerConfiguration servConf = new ServerConfiguration(confByIndex(0));
+        Auditor auditor = new 
Auditor(BookieImpl.getBookieId(servConf).toString(), servConf, bkc, false,
+                NullStatsLogger.INSTANCE);
+        auditor.start();
+        killBookie(addressByIndex(1));
+        Awaitility.await().until(() -> auditor.getAuditTask() != null);
+
+        assertShutsDownPromptly(auditor);
+    }
+
+    /**
+     * Test that shutting down an auditor doesn't wait for an audit that waits
+     * for the ledger replication to be enabled.
+     */
+    @Test
+    public void testShutdownWithAuditWaitingForReplication() throws Exception {
+        for (AuditorElector e : auditorElectors.values()) {
+            e.shutdown();
+        }
+        LedgerUnderreplicationManager urm = 
driver.getLedgerManagerFactory().newLedgerUnderreplicationManager();
+        urm.disableLedgerReplication();
+
+        ServerConfiguration servConf = new ServerConfiguration(confByIndex(0));
+        // start() submits a single bookie check, which waits for the 
replication to be enabled
+        servConf.setAuditorPeriodicBookieCheckInterval(0);
+        Auditor auditor = new 
Auditor(BookieImpl.getBookieId(servConf).toString(), servConf, bkc, false,
+                NullStatsLogger.INSTANCE);
+        auditor.start();
+
+        assertShutsDownPromptly(auditor);

Review Comment:
   `start()` only submits the bookie check; it does not wait for it to reach 
the replication-disabled wait. The asynchronous shutdown can therefore win the 
race and discard the still-queued check, letting this test pass without 
exercising interruption of a running audit. Please wait for an explicit signal 
that the check has entered the replication-wait path (for example, a latch 
around `notifyLedgerReplicationEnabled`) before calling 
`assertShutsDownPromptly`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to