Repository: zeppelin
Updated Branches:
  refs/heads/master eeabbe23e -> 399c49b4e


ZEPPELIN-1063: fix PythonInterpreter flaky test

### What is this PR for?
 fix flaky `PythonInterpreter.testClose()` test

### What type of PR is it?
Hot Fix

### What is the Jira issue?
[ZEPPELIN-1063](https://issues.apache.org/jira/browse/ZEPPELIN-1063)

### How should this be tested?
CI should pass

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: Alexander Bezzubov <[email protected]>

Closes #1134 from bzz/ZEPPELIN-1063/python/add-retrys and squashes the 
following commits:

65698d2 [Alexander Bezzubov] Reduce :sleeping: time in python interpreter 
unit-test
1be7732 [Alexander Bezzubov] Adding timeout for py4j gateway to have time to 
shutdown
3529fe5 [Alexander Bezzubov] fix PythonInterpreterTest.testClose() test


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/399c49b4
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/399c49b4
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/399c49b4

Branch: refs/heads/master
Commit: 399c49b4e1f62e120bd0efe8a00ce3e7bfe4f8cc
Parents: eeabbe2
Author: Alexander Bezzubov <[email protected]>
Authored: Thu Jul 7 11:33:20 2016 +0900
Committer: Alexander Bezzubov <[email protected]>
Committed: Thu Jul 7 12:47:11 2016 +0900

----------------------------------------------------------------------
 .../zeppelin/python/PythonInterpreterTest.java  | 23 ++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/399c49b4/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
----------------------------------------------------------------------
diff --git 
a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java 
b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
index c9fee13..7e4e42f 100644
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
@@ -38,6 +38,7 @@ import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.zeppelin.interpreter.InterpreterResult;
 import org.junit.Before;
@@ -110,13 +111,10 @@ public class PythonInterpreterTest {
 
   /**
    * If Py4J installed, bootstrap_input.py
-   * is sent to interpreter and JavaGateway is
-   * running
-   *
-   * @throws IOException
+   * is sent to interpreter and JavaGateway is running
    */
   @Test
-  public void testPy4jInstalled() throws IOException {
+  public void testPy4jInstalled() throws IOException, InterruptedException {
     when(mockPythonProcess.sendAndGetResult(eq("\n\nimport 
py4j\n"))).thenReturn(">>>");
 
     pythonInterpreter.open();
@@ -131,6 +129,9 @@ public class PythonInterpreterTest {
     assertTrue(cmdHistory.contains("org.apache.zeppelin.display.Input"));
 
     assertTrue(serverIsListeningOn(py4jPort));
+    pythonInterpreter.close();
+    TimeUnit.MILLISECONDS.sleep(100);
+    assertFalse(serverIsListeningOn(py4jPort));
   }
 
   @Test
@@ -144,6 +145,7 @@ public class PythonInterpreterTest {
 
     //when
     pythonInterpreter.close();
+    TimeUnit.MILLISECONDS.sleep(100);
 
     //then
     assertFalse(serverIsListeningOn(py4jPort));
@@ -164,13 +166,16 @@ public class PythonInterpreterTest {
    * @param port
    */
   private boolean serverIsListeningOn(Integer port) {
-    boolean serverIsListening = false;
     Socket s = new Socket();
+    boolean serverIsListening = false;
 
-    boolean connected = tryToConnect(s, port);
-    if (connected) {
-      serverIsListening = true;
+    int retryCount = 0;
+    boolean connected = false;
+    while (connected = tryToConnect(s, port) && retryCount < 10) {
+      serverIsListening = connected;
       tryToClose(s);
+      retryCount++;
+      s = new Socket();
     }
     return serverIsListening;
   }

Reply via email to