Bladeren bron

Add tracing to nullpointer in RerunTestResultProcessor (#72796)

- also catch IllegalArgumentException and provide more debug output
Rene Groeschke 4 jaren geleden
bovenliggende
commit
148de22493

+ 41 - 10
buildSrc/src/main/java/org/elasticsearch/gradle/internal/test/rerun/executer/RerunTestResultProcessor.java

@@ -30,7 +30,7 @@ final class RerunTestResultProcessor implements TestResultProcessor {
      * being the root element. This is required to be tracked here to get the
      * structure right when rerunning a test task tests.
      * */
-    private Object rootTestDescriptorId;
+    private TestDescriptorInternal rootTestDescriptor;
 
     RerunTestResultProcessor(TestResultProcessor delegate) {
         this.delegate = delegate;
@@ -39,13 +39,21 @@ final class RerunTestResultProcessor implements TestResultProcessor {
     @Override
     public void started(TestDescriptorInternal descriptor, TestStartEvent testStartEvent) {
         activeDescriptorsById.put(descriptor.getId(), descriptor);
-        if (rootTestDescriptorId == null) {
-            rootTestDescriptorId = descriptor.getId();
-            delegate.started(descriptor, testStartEvent);
-        } else if (descriptor.getId().equals(rootTestDescriptorId) == false) {
+        if (rootTestDescriptor == null) {
+            rootTestDescriptor = descriptor;
+            try {
+                delegate.started(descriptor, testStartEvent);
+            } catch (IllegalArgumentException illegalArgumentException) {
+                logTracing(descriptor.getId(), illegalArgumentException);
+            }
+        } else if (descriptor.getId().equals(rootTestDescriptor.getId()) == false) {
             boolean active = activeDescriptorsById.containsKey(testStartEvent.getParentId());
             if (active) {
-                delegate.started(descriptor, testStartEvent);
+                try {
+                    delegate.started(descriptor, testStartEvent);
+                } catch (IllegalArgumentException illegalArgumentException) {
+                    logTracing(descriptor.getId(), illegalArgumentException);
+                }
             }
         }
     }
@@ -53,7 +61,7 @@ final class RerunTestResultProcessor implements TestResultProcessor {
     @Override
     public void completed(Object testId, TestCompleteEvent testCompleteEvent) {
         boolean active = activeDescriptorsById.containsKey(testId);
-        if (testId.equals(rootTestDescriptorId)) {
+        if (testId.equals(rootTestDescriptor.getId())) {
             if (activeDescriptorsById.size() != 1) {
                 return;
             }
@@ -61,14 +69,22 @@ final class RerunTestResultProcessor implements TestResultProcessor {
             activeDescriptorsById.remove(testId);
         }
         if (active) {
-            delegate.completed(testId, testCompleteEvent);
+            try {
+                delegate.completed(testId, testCompleteEvent);
+            } catch (IllegalArgumentException illegalArgumentException) {
+                logTracing(testId, illegalArgumentException);
+            }
         }
     }
 
     @Override
     public void output(Object testId, TestOutputEvent testOutputEvent) {
         if (activeDescriptorsById.containsKey(testId)) {
-            delegate.output(testId, testOutputEvent);
+            try {
+                delegate.output(testId, testOutputEvent);
+            } catch (IllegalArgumentException illegalArgumentException) {
+                logTracing(testId, illegalArgumentException);
+            }
         }
     }
 
@@ -76,12 +92,27 @@ final class RerunTestResultProcessor implements TestResultProcessor {
     public void failure(Object testId, Throwable throwable) {
         if (activeDescriptorsById.containsKey(testId)) {
             activeDescriptorsById.remove(testId);
-            delegate.failure(testId, throwable);
+            try {
+                delegate.failure(testId, throwable);
+            } catch (IllegalArgumentException illegalArgumentException) {
+                logTracing(testId, illegalArgumentException);
+            }
+        }
+    }
+
+    private void logTracing(Object testId, IllegalArgumentException illegalArgumentException) {
+        // Add tracing to diagnose why we see this on CI
+        System.out.println("Rerun failure test id = " + testId);
+        System.out.println("Active test descriptors:");
+        for (Map.Entry<Object, TestDescriptorInternal> entry : activeDescriptorsById.entrySet()) {
+            System.out.println("id= " + entry.getKey() + " -- " + entry.getValue().getDisplayName());
         }
+        illegalArgumentException.printStackTrace();
     }
 
     public void reset() {
         this.activeDescriptorsById.clear();
+        this.activeDescriptorsById.put(rootTestDescriptor.getId(), rootTestDescriptor);
     }
 
     public List<TestDescriptorInternal> getActiveDescriptors() {