kezhuw commented on a change in pull request #13593:
URL: https://github.com/apache/flink/pull/13593#discussion_r503408507



##########
File path: 
flink-connectors/flink-connector-base/src/test/java/org/apache/flink/connector/base/source/reader/fetcher/SplitFetcherTest.java
##########
@@ -120,16 +120,16 @@ public void testNotifiesWhenGoingIdleConcurrent() throws 
Exception {
                final SplitFetcher<Object, TestingSourceSplit> fetcher = 
createFetcherWithSplit(
                        "test-split", queue, new 
TestingSplitReader<>(finishedSplitFetch("test-split")));
 
-               final QueueDrainerThread queueDrainer = new 
QueueDrainerThread(queue);
+               final QueueDrainerThread queueDrainer = new 
QueueDrainerThread(queue, fetcher, 1);
                queueDrainer.start();
 
-               try {
-                       fetcher.runOnce();
+               fetcher.runOnce();
 
-                       assertTrue(queue.getAvailabilityFuture().isDone());
-               } finally {
-                       queueDrainer.shutdown();
-               }
+               queueDrainer.sync();
+
+               // either we got the notification that the fetcher went idle 
after the queue was drained (thread finished)
+               // or the fetcher was already idle when the thread drained the 
queue (then we need no additional notification)
+               assertTrue(queue.getAvailabilityFuture().isDone() || 
queueDrainer.wasIdleWhenFinished());

Review comment:
       Nice assertion. I think this assertion holds because of:
   * Inside `SplitFetcher.checkAndSetIdle`, `isIdle = true` happens before 
`elementsQueue.notifyAvailable()`, and both are atomic.
   * In queue drainer thread, if `queue.poll`, which is also atomic, happens 
before `elementsQueue.notifyAvailable()` then 
`queue.getAvailabilityFuture().isDone()` holds, otherwise, 
`queueDrainer.wasIdleWhenFinished()` holds.




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

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


Reply via email to