mattday9 commented on code in PR #25681:
URL: https://github.com/apache/pulsar/pull/25681#discussion_r3206434140


##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/delayed/InMemoryDeliveryTrackerTest.java:
##########
@@ -274,4 +279,111 @@ public void 
testDelaySequence(InMemoryDelayedDeliveryTracker tracker) throws Exc
         tracker.close();
     }
 
+    @Test(dataProvider = "delayedTracker")
+    public void 
testAddMultipleMessagesSameWindow(InMemoryDelayedDeliveryTracker tracker) 
throws Exception {
+        tracker.addMessage(1, 1, 50);
+        tracker.addMessage(1, 1, 50);
+        tracker.addMessage(1, 1, 50);
+
+        clockTime.set(60);
+
+        tracker.getScheduledMessages(10);
+    }
+
+    @Test(dataProvider = "delayedTracker")
+    public void testRaceConditionInUpdateTimer(InMemoryDelayedDeliveryTracker 
tracker) throws Exception {
+        final int numThreads = 16;
+        final int operationsPerThread = 1000;
+        final CountDownLatch startLatch = new CountDownLatch(1);
+        final CountDownLatch doneLatch = new CountDownLatch(numThreads);
+        final AtomicInteger errors = new AtomicInteger(0);
+        final AtomicReference<Exception> firstException = new 
AtomicReference<>();
+
+        @Cleanup("shutdown")
+        ExecutorService executorService = Executors.newFixedThreadPool(32);
+
+        for (int i = 0; i < 2; i++) {
+            executorService.submit(() -> {
+                try {
+                    startLatch.await();
+                    for (int j = 0; j < operationsPerThread; j++) {
+                        tracker.clear();
+                        Thread.sleep(1);
+                    }
+                } catch (Exception e) {
+                    errors.incrementAndGet();
+                    firstException.compareAndSet(null, e);
+                    e.printStackTrace();
+                } finally {
+                    doneLatch.countDown();
+                }
+            });
+        }
+
+        for (int i = 0; i < 5; i++) {
+            executorService.submit(() -> {
+                try {
+                    startLatch.await();
+                    for (int j = 0; j < operationsPerThread; j++) {
+                        tracker.addMessage(1, 1, 10);
+                        Thread.sleep(1);
+                    }
+                } catch (Exception e) {
+                    errors.incrementAndGet();
+                    firstException.compareAndSet(null, e);
+                    e.printStackTrace();
+                } finally {
+                    doneLatch.countDown();
+                }
+            });
+        }
+
+        for (int i = 0; i < 5; i++) {

Review Comment:
   Magic number - use descriptive variables



-- 
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