PIG-5320: TestCubeOperator#testRollupBasic is flaky on Spark 2.2 (nkollar via szita)

git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1821165 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index c1f3e48..3421b59 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -64,6 +64,8 @@
  
 BUG FIXES
 
+PIG-5320: TestCubeOperator#testRollupBasic is flaky on Spark 2.2 (nkollar via szita)
+
 PIG-5327: Check for DAG status before trying to kill (rohini)
 
 PIG-5325: Schema disambiguation can't be turned off for nested schemas (szita)
diff --git a/src/org/apache/pig/backend/hadoop/executionengine/spark/JobStatisticCollector.java b/src/org/apache/pig/backend/hadoop/executionengine/spark/JobStatisticCollector.java
index 8e16eac..abbd76e 100644
--- a/src/org/apache/pig/backend/hadoop/executionengine/spark/JobStatisticCollector.java
+++ b/src/org/apache/pig/backend/hadoop/executionengine/spark/JobStatisticCollector.java
@@ -52,15 +52,13 @@
         }
     }
 
-    public boolean waitForJobToEnd(int jobId) throws InterruptedException {
+    public void waitForJobToEnd(int jobId) throws InterruptedException {
         synchronized (sparkListener) {
-            if (finishedJobIds.contains(jobId)) {
-                finishedJobIds.remove(jobId);
-                return true;
+            while (!finishedJobIds.contains(jobId)) {
+                sparkListener.wait();
             }
 
-            sparkListener.wait();
-            return false;
+            finishedJobIds.remove(jobId);
         }
     }