reswqa commented on code in PR #22422:
URL: https://github.com/apache/flink/pull/22422#discussion_r1171387869


##########
flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultLeaderElectionServiceTest.java:
##########
@@ -301,35 +383,119 @@ void testServiceShutDownWithSynchronizedDriver() throws 
Exception {
                 Preconditions.checkNotNull(
                         
testingLeaderElectionDriverFactory.getCurrentLeaderDriver());
 
-        final CheckedThread isLeaderThread =
-                new CheckedThread() {
-                    @Override
-                    public void go() {
-                        currentLeaderDriver.isLeader();
-                    }
-                };
-        isLeaderThread.start();
+        currentLeaderDriver.isLeader();
 
         leaderElectionService.stop();
-        isLeaderThread.sync();
+    }
+
+    @Test
+    void testOnLeadershipChangeDoesNotBlock() throws Exception {
+        new Context() {
+            {
+                runTestWithManuallyTriggeredEvents(
+                        executorService -> {
+                            final UUID expectedSessionID = UUID.randomUUID();
+
+                            
testingLeaderElectionDriver.isLeader(expectedSessionID);
+                            executorService.trigger();
+
+                            testingContender.waitForLeader();
+
+                            // this call would time out if the
+                            // DefaultLeaderElectionService.onLeadershipChange 
would be called
+                            // synchronously
+                            
testingLeaderElectionDriver.leaderInformationChanged(
+                                    LeaderInformation.empty());
+
+                            
assertThat(testingLeaderElectionDriver.getLeaderInformation().isEmpty())
+                                    .isTrue();
+
+                            executorService.trigger();
+
+                            assertThat(
+                                            testingLeaderElectionDriver
+                                                    .getLeaderInformation()
+                                                    .getLeaderSessionID())
+                                    .isEqualTo(expectedSessionID);
+                        });
+            }
+        };
+    }
+
+    @Test
+    void testOnGrantLeadershipAsyncDoesNotBlock() throws Exception {
+        new Context() {
+            {
+                runTestWithManuallyTriggeredEvents(
+                        executorService -> {
+                            final UUID expectedSessionID = UUID.randomUUID();
+                            
testingLeaderElectionDriver.isLeader(expectedSessionID);
+
+                            
assertThat(leaderElectionService.getLeaderSessionID()).isNull();
+
+                            executorService.trigger();
+
+                            
assertThat(leaderElectionService.getLeaderSessionID())
+                                    .isEqualTo(expectedSessionID);
+                        });
+            }
+        };
+    }
+
+    @Test
+    void testOnRevokeLeadershipDoesNotBlock() throws Exception {

Review Comment:
   To be honest, I didn't understand the intention of this test. If we run it 
in a synchronized manner, it shouldn't timeout either.



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