I have a testng gui test, where I am using org.fest.swing APIs. It has 3 testcases where at the end of each it tries to close a dialog. When executing, it randomly hangs at a dialog box where it should click on one of the button and later fails at an assert condition.
Example:
DialogFixture saveChangesDialog = WindowFinder.findDialog(SAVE).using(robot);
String buttonText = saveChanges ? "Yes" : "No";
saveChangesDialog.button(JButtonMatcher.withText(buttonText)).click();
and assert condition is:
assertThat(ComponentVisibleQuery.isVisible(target)).isFalse();
It fails many of the times (not always). When executing single test it passes always. Unable to identify the reason for failure.
Found a similar reference, but it didn't work. https://github.com/joel-costigliola/assertj-swing/issues/30
---------- EDIT 1 ----------
On more analysis found that in same method, a thread is started to close Frame. It has single line in run() :- org.fest.swing.fixture.JInternalFrameFixture.close();
After initiating this thread, main thread calls the above mentioned Dialog (given in above example). Later main thread calls t.join(5000) ... to check if the thread task is completed. And later checks that the Frame visibility is false.
assertThat(ComponentVisibleQuery.isVisible(target)).isFalse();
In all fail scenarios, the thread state is WAITING and on printing stackTrace :-
10:19:32 [testng] Thread State: WAITING 10:19:32 [testng] StackTrace1 [sun.misc.Unsafe.park(Native Method), java.util.concurrent.locks.LockSupport.park(LockSupport.java:175), java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836), java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997), java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304), java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231), org.fest.swing.edt.GuiActionRunner.run(GuiActionRunner.java:117), org.fest.swing.edt.GuiActionRunner.execute(GuiActionRunner.java:96), org.fest.swing.driver.JInternalFrameCloseTask.close(JInternalFrameCloseTask.java:33), org.fest.swing.driver.JInternalFrameDriver.close(JInternalFrameDriver.java:339), org.fest.swing.fixture.JInternalFrameFixture.close(JInternalFrameFixture.java:150),
So this means, that because thread is in WAITING state and stuck at some lock condition, its not able to close Frame, and so the assert condition fails.
Updated time to 500 seconds, still its in WAITING state for failure scenarios. Unable to find why the thread is stuck in waiting state.