Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13497#discussion_r65928683
  
    --- Diff: 
launcher/src/test/java/org/apache/spark/launcher/LauncherServerSuite.java ---
    @@ -152,6 +157,69 @@ public void testTimeout() throws Exception {
         }
       }
     
    +  @Test
    +  public void testSparkSubmitVmShutsDown() throws Exception {
    +    ChildProcAppHandle handle = LauncherServer.newAppHandle();
    +    TestClient client = null;
    +    final List<SparkAppHandle.State> expectedStateList = 
Arrays.asList(SparkAppHandle.State.CONNECTED, SparkAppHandle.State.LOST);
    +    final List<SparkAppHandle.State> realStateList = new 
ArrayList<SparkAppHandle.State>(2);
    +    final AtomicBoolean jobFinished = new AtomicBoolean(false);
    +    final BlockingQueue<SparkAppHandle.State> stateQueue = new 
LinkedBlockingQueue<SparkAppHandle.State>(10);
    +    final Semaphore semaphore = new Semaphore(0);
    +    try {
    +      Socket s = new Socket(InetAddress.getLoopbackAddress(),
    +        LauncherServer.getServerInstance().getPort());
    +      handle.addListener(new SparkAppHandle.Listener() {
    +        public void stateChanged(SparkAppHandle handle) {
    +          stateQueue.offer(handle.getState());
    +          semaphore.release();
    +        }
    +        public void infoChanged(SparkAppHandle handle) {
    +          semaphore.release();
    +        }
    +      });
    +      client = new TestClient(s);
    +      client.send(new Hello(handle.getSecret(), "1.4.0"));
    +      assertTrue(semaphore.tryAcquire(30, TimeUnit.SECONDS));
    +      // Make sure the server matched the client to the handle.
    +      assertNotNull(handle.getConnection());
    +      Thread sparkLauncherClient = new Thread() {
    +        public void run() {
    +          while (!jobFinished.get()) {
    +            SparkAppHandle.State state = SparkAppHandle.State.UNKNOWN;
    +            try {
    +              state = (SparkAppHandle.State)stateQueue.take();
    +            } catch (InterruptedException e) {
    +              Thread.currentThread().interrupt();
    +              throw new RuntimeException(e);
    +            }
    +            switch (state) {
    +              case CONNECTED:
    +                realStateList.add(state);
    +                break;
    +              case LOST:
    +                jobFinished.set(true);
    +                realStateList.add(state);
    +                break;
    +              default:
    +                throw new RuntimeException(String.format("Unexpected 
state. The should have been one of the %s.", expectedStateList));
    +            }
    +          }
    +        }
    +      };
    +      sparkLauncherClient.start();
    +      close(client);
    +      sparkLauncherClient.join(10000L);
    --- End diff --
    
    Do you need this separate thread? Seems to me like all you need is:
    
    ```
    close(client);
    assertTrue(semaphore.tryAcquire(30, TimeUnit.SECONDS));
    assertEquals(SparkAppHandle.State.LOST, handle.getState());
    ```
    
    That gets rid of a bunch of code in your tests and tests just the code 
you're interested in.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to