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


##########
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/JobMasterServiceLeadershipRunnerTest.java:
##########
@@ -683,21 +665,66 @@ public void testJobAlreadyDone() throws Exception {
                     jobManagerRunner.getResultFuture();
 
             JobManagerRunnerResult result = resultFuture.get();
-            assertEquals(
-                    JobStatus.FAILED,
-                    
result.getExecutionGraphInfo().getArchivedExecutionGraph().getState());
+            
assertThat(result.getExecutionGraphInfo().getArchivedExecutionGraph().getState())
+                    .isEqualTo(JobStatus.FAILED);
         }
     }
 
+    @Test
+    void 
testJobMasterServiceLeadershipRunnerCloseWhenElectionServiceGrantLeaderShip()
+            throws Exception {
+        final TestingLeaderElectionDriver.TestingLeaderElectionDriverFactory
+                testingLeaderElectionDriverFactory =
+                        new 
TestingLeaderElectionDriver.TestingLeaderElectionDriverFactory();
+        final LeaderElectionService defaultLeaderElectionService =
+                new 
DefaultLeaderElectionService(testingLeaderElectionDriverFactory);
+
+        final JobMasterServiceLeadershipRunner jobManagerRunner =
+                newJobMasterServiceLeadershipRunnerBuilder()
+                        .setJobMasterServiceProcessFactory(
+                                
TestingJobMasterServiceProcessFactory.newBuilder().build())
+                        .setLeaderElectionService(defaultLeaderElectionService)
+                        .build();
+
+        jobManagerRunner.start();
+        final TestingLeaderElectionDriver currentLeaderDriver =
+                Preconditions.checkNotNull(
+                        
testingLeaderElectionDriverFactory.getCurrentLeaderDriver());
+
+        final CheckedThread contenderCloseThread =
+                new CheckedThread() {
+                    @Override
+                    public void go() {
+                        try {
+                            jobManagerRunner.close();
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                    }
+                };
+        contenderCloseThread.start();
+
+        // grant leadership.
+        currentLeaderDriver.isLeader();

Review Comment:
   @XComp Thank you for your advice. 
   At the beginning, I didn't think of a good way to control the completion of 
completableFuture, and the probability of deadlock reproduce in my local 
environment is very high. But your suggestion did find a good control injection 
point, so i decided to test it in this way. 
   But if we want to reproduce the problem 100%, it seems that we need another 
control point. Maybe `TestingLeaderElectionDriver#isLeader` is a suitable 
choice. What's your opinion?



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to