[hg] main-silver: #229250: Randomly failing unittest

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #229250: Randomly failing unittest
  • Date: Tue, 04 Jun 2013 13:34:07 -0700

changeset d09ecf0ecc08 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/d09ecf0ecc08
description:
        #229250: Randomly failing unittest

        Fix an unreliable unittest, that suffers a race condition (swing event
        handling, filesystem event delivery and test execution flow). The 
attached
        patch places blocks on the relevant filesystem queues and swing 
threads.

        Patch by Matthias42.

diffstat:

 
db/test/unit/src/org/netbeans/api/db/explorer/support/DatabaseExplorerUIsTest.java
 |   5 +-
 db/test/unit/src/org/netbeans/modules/db/test/TestBase.java                  
      |  34 ++++++++++
 2 files changed, 38 insertions(+), 1 deletions(-)

diffs (78 lines):

diff --git 
a/db/test/unit/src/org/netbeans/api/db/explorer/support/DatabaseExplorerUIsTest.java
 
b/db/test/unit/src/org/netbeans/api/db/explorer/support/DatabaseExplorerUIsTest.java
--- 
a/db/test/unit/src/org/netbeans/api/db/explorer/support/DatabaseExplorerUIsTest.java
+++ 
b/db/test/unit/src/org/netbeans/api/db/explorer/support/DatabaseExplorerUIsTest.java
@@ -41,7 +41,6 @@
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
-
 package org.netbeans.api.db.explorer.support;
 
 import javax.swing.JComboBox;
@@ -111,12 +110,16 @@
         DatabaseConnection dc = 
DatabaseConnection.create(Util.createDummyDriver(), "dc1", "user", "schema", 
"password", true);
         ConnectionManager.getDefault().addConnection(dc);
 
+        forceFlush();
+
         assertEquals("Wrong number of items in the combobox", 4, 
combo.getItemCount());
 
         assertSame(dc, combo.getItemAt(2));
 
         ConnectionManager.getDefault().removeConnection(dc);
 
+        forceFlush();
+
         assertEquals("Wrong number of items in the combobox", 3, 
combo.getItemCount());
 
         assertSame(dbconn2, combo.getItemAt(0));
diff --git a/db/test/unit/src/org/netbeans/modules/db/test/TestBase.java 
b/db/test/unit/src/org/netbeans/modules/db/test/TestBase.java
--- a/db/test/unit/src/org/netbeans/modules/db/test/TestBase.java
+++ b/db/test/unit/src/org/netbeans/modules/db/test/TestBase.java
@@ -44,7 +44,12 @@
 
 package org.netbeans.modules.db.test;
 
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import javax.swing.SwingUtilities;
 import org.netbeans.junit.NbTestCase;
+import org.openide.filesystems.FileSystem;
+import org.openide.filesystems.FileUtil;
 
 /**
  * Common ancestor for all test classes.
@@ -59,4 +64,33 @@
         super(name);
     }
 
+    /**
+     * Force flush of config filesystem and EDT.
+     *
+     * Make sure outstanding writes to the config filesystem and outstanding
+     * events on the EDT are flushed
+     */
+    protected void forceFlush() {
+        if (SwingUtilities.isEventDispatchThread()) {
+            throw new IllegalStateException(
+                    "forceFlush might only be called off the EDT!");
 }
+        try {
+            FileUtil.getConfigRoot().getFileSystem()
+                    .runAtomicAction(new FileSystem.AtomicAction() {
+                        @Override
+                        public void run() throws IOException {
+                            // NOOP - force a wait
+                        }
+                    });
+            SwingUtilities.invokeAndWait(new Runnable() {
+                @Override
+                public void run() {
+                    // NOOP - force a wait
+                }
+            });
+        } catch (IOException | InterruptedException | 
InvocationTargetException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+}

[hg] main-silver: #229250: Randomly failing unittest

Jaroslav Havlin 06/04/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close