This is an automated email from the ASF dual-hosted git repository. penghui pushed a commit to branch branch-2.7 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 1604cd7610d28ed9be547a13d8a23bd6f35a0ca2 Author: Matteo Merli <[email protected]> AuthorDate: Fri Jan 8 16:54:09 2021 -0800 Fixed race condition in ManagedLedgerTest.testAsyncUpdateProperties() (#9152) ### Motivation The test is intermittently failing because the check is disregarding the timing of when the first callback is received, which can be later than the 3 async call is issued. (cherry picked from commit f10f1ce2ea51237273eaf2a7252f51e2f779c434) --- .../bookkeeper/mledger/impl/ManagedLedgerTest.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java index 35f7921..246e06a 100644 --- a/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java +++ b/managed-ledger/src/test/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerTest.java @@ -1198,50 +1198,57 @@ public class ManagedLedgerTest extends MockedBookKeeperTestCase { @Test public void testAsyncUpdateProperties() throws Exception { - final CountDownLatch latch = new CountDownLatch(3); + ManagedLedger ledger = factory.open("my_test_ledger"); Map<String, String> prop = new HashMap<>(); prop.put("key1", "value1"); prop.put("key2", "value2"); prop.put("key3", "value3"); + + final CountDownLatch latch1 = new CountDownLatch(1); ledger.asyncSetProperties(prop, new AsyncCallbacks.UpdatePropertiesCallback() { @Override public void updatePropertiesComplete(Map<String, String> properties, Object ctx) { assertEquals(prop, properties); - latch.countDown(); + latch1.countDown(); } @Override public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) { } }, null); + assertTrue(latch1.await(5, TimeUnit.SECONDS)); + final CountDownLatch latch2 = new CountDownLatch(1); ledger.asyncSetProperty("key4", "value4", new AsyncCallbacks.UpdatePropertiesCallback() { @Override public void updatePropertiesComplete(Map<String, String> properties, Object ctx) { assertNotNull(properties.get("key4")); assertEquals("value4", properties.get("key4")); - latch.countDown(); + latch2.countDown(); } @Override public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) { } }, null); + assertTrue(latch2.await(5, TimeUnit.SECONDS)); prop.remove("key1"); + + final CountDownLatch latch3 = new CountDownLatch(1); ledger.asyncDeleteProperty("key1", new AsyncCallbacks.UpdatePropertiesCallback() { @Override public void updatePropertiesComplete(Map<String, String> properties, Object ctx) { assertNull(properties.get("key1")); - latch.countDown(); + latch3.countDown(); } @Override public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) { } }, null); - assertTrue(latch.await(60, TimeUnit.SECONDS)); + assertTrue(latch3.await(5, TimeUnit.SECONDS)); } @Test
