You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/21 11:37:12 UTC

[GitHub] [pulsar] congbobo184 commented on a diff in pull request #18147: [fix][test] Fix flaky test `testDoNotGetOffloadPoliciesMultipleTimesWhenTrimLedgers`

congbobo184 commented on code in PR #18147:
URL: https://github.com/apache/pulsar/pull/18147#discussion_r1001686399


##########
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java:
##########
@@ -3624,6 +3624,8 @@ public void testDoNotGetOffloadPoliciesMultipleTimesWhenTrimLedgers() throws Exc
         LedgerOffloader ledgerOffloader = mock(NullLedgerOffloader.class);
         OffloadPoliciesImpl offloadPolicies = mock(OffloadPoliciesImpl.class);
         when(ledgerOffloader.getOffloadPolicies()).thenReturn(offloadPolicies);
+        when(ledgerOffloader.offload(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(null));
+        when(ledgerOffloader.getOffloadPolicies().getManagedLedgerOffloadThresholdInBytes()).thenReturn(-1L);

Review Comment:
   ```suggestion
           when(offloadPolicies.getManagedLedgerOffloadThresholdInBytes()).thenReturn(-1L);
   ```
   may only add this logic the test can become stable.
   leger.close() will invoke `ledgerOffloader.getOffloadPolicies().getManagedLedgerOffloadThresholdInBytes()`
   
   the first ledgerOffloader will open a timer task to call
   https://github.com/apache/pulsar/blob/fa328a42d5770a27237d926eac97385284876174/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java#L2395
   so we don't open this timer task is enough
   



##########
managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java:
##########
@@ -3643,7 +3645,10 @@ public void testDoNotGetOffloadPoliciesMultipleTimesWhenTrimLedgers() throws Exc
         config.setLedgerOffloader(ledgerOffloader);
 
         ledger.internalTrimConsumedLedgers(Futures.NULL_PROMISE);
-        verify(ledgerOffloader, times(1)).getOffloadPolicies();
+        final LedgerOffloader finalLedgerOffloader = ledgerOffloader;
+        Awaitility.await().untilAsserted(() -> {
+            verify(finalLedgerOffloader, times(1)).getOffloadPolicies();
+        });

Review Comment:
   ```suggestion
   
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org