JBR-1905 [TESBUG] java/awt/TextArea/DisposeTest/TestDispose.java: frame is not disposed

- java/awt/TextArea/DisposeTest/TestDispose.java, java/awt/TextField/DisposeTest/TestDispose.java: fixed test frame disposal
- java/awt/Frame/DisposeStressTest/DisposeStressTest.java: decreased test timeout from 2h to 10 min, added minor diagnostic logging

(cherry picked from commit 7f025f4e16)
(cherry picked from commit dda7f3d871)
(cherry picked from commit bc09aadadb)
This commit is contained in:
Elena Sayapina
2020-12-21 13:55:31 +07:00
committed by alexey.ushakov@jetbrains.com
parent e7e7fba5d3
commit 64d8f61882
3 changed files with 86 additions and 55 deletions

View File

@@ -27,7 +27,7 @@
@bug 4051487 4145670
@summary Tests that disposing of an empty Frame or a Frame with a MenuBar
while it is being created does not crash the VM.
@run main/timeout=7200 DisposeStressTest
@run main/timeout=600 DisposeStressTest
*/
import java.awt.Frame;
@@ -39,6 +39,7 @@ public class DisposeStressTest {
public static void main(final String[] args) {
for (int i = 0; i < 1000; i++) {
System.out.println("i = " + i);
Frame f = new Frame();
f.setBounds(10, 10, 10, 10);
f.show();

View File

@@ -38,12 +38,15 @@ import java.awt.Frame;
import java.awt.TextArea;
import java.awt.Robot;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class TestDispose {
public static final int TIMEOUT = 30;
public static Frame frame = null;
public static TextArea textArea = null;
public static volatile Process worker = null;
@@ -57,33 +60,33 @@ public class TestDispose {
ex.printStackTrace();
throw new RuntimeException("Unexpected failure");
}
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame("Test");
textArea = new TextArea("editable textArea");
textArea.setEditable(true);
// textArea.setEditable(false); // this testcase passes if textArea is non-editable
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame("Test");
frame.setLayout(new FlowLayout());
frame.add(textArea);
textArea = new TextArea("editable textArea");
textArea.setEditable(true);
// textArea.setEditable(false); // this testcase passes if textArea is non-editable
frame.setLayout(new FlowLayout());
frame.add(textArea);
frame.pack();
frame.setVisible(true);
}
});
robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.dispose();
}
});
robot.waitForIdle();
frame.pack();
frame.setVisible(true);
}
});
robot.waitForIdle();
} finally {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.dispose();
}
});
robot.waitForIdle();
}
}
public static void main(String[] args) throws Exception{
@@ -94,10 +97,21 @@ public class TestDispose {
}
});
System.out.println(System.getProperty("java.home")+"/bin/java TestDispose workprocess");
worker = Runtime.getRuntime().exec(System.getProperty("java.home")+"/bin/java TestDispose workprocess");
worker.waitFor();
return;
System.out.println(System.getProperty("java.home") + "/bin/java -cp "
+ System.getProperty("java.class.path") + " " + TestDispose.class.getName() + " workprocess");
worker = new ProcessBuilder(System.getProperty("java.home")+"/bin/java",
"-cp", System.getProperty("java.class.path"), TestDispose.class.getName(), "workprocess")
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start();
if(worker.waitFor(TIMEOUT, TimeUnit.SECONDS)) {
if(worker.exitValue() != 0) {
throw new RuntimeException("TEST ERROR: subprocess has finished abnormally");
}
System.out.println("TEST PASSED");
return;
} else {
throw new RuntimeException("TEST FAILED: subprocess has not finished for " + TIMEOUT + " sec");
}
}
TestDispose app = new TestDispose();

View File

@@ -38,12 +38,15 @@ import java.awt.Frame;
import java.awt.TextField;
import java.awt.Robot;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class TestDispose {
public static final int TIMEOUT = 30;
public static Frame frame = null;
public static TextField textField = null;
public static volatile Process worker = null;
@@ -58,31 +61,33 @@ public class TestDispose {
throw new RuntimeException("Unexpected failure");
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame("Test");
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame("Test");
textField = new TextField("editable textArea");
textField.setEditable(true);
// textField.setEditable(false); // this testcase passes if textField is non-editable
textField = new TextField("editable textArea");
textField.setEditable(true);
// textField.setEditable(false); // this testcase passes if textField is non-editable
frame.setLayout(new FlowLayout());
frame.add(textField);
frame.setLayout(new FlowLayout());
frame.add(textField);
frame.pack();
frame.setVisible(true);
}
});
robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.dispose();
}
});
robot.waitForIdle();
frame.pack();
frame.setVisible(true);
}
});
robot.waitForIdle();
} finally {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.dispose();
}
});
robot.waitForIdle();
}
}
@@ -94,10 +99,21 @@ public class TestDispose {
}
});
System.out.println(System.getProperty("java.home")+"/bin/java TestDispose workprocess");
worker = Runtime.getRuntime().exec(System.getProperty("java.home")+"/bin/java TestDispose workprocess");
worker.waitFor();
return;
System.out.println(System.getProperty("java.home") + "/bin/java -cp "
+ System.getProperty("java.class.path") + " " + TestDispose.class.getName() + " workprocess");
worker = new ProcessBuilder(System.getProperty("java.home")+"/bin/java",
"-cp", System.getProperty("java.class.path"), TestDispose.class.getName(), "workprocess")
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start();
if(worker.waitFor(TIMEOUT, TimeUnit.SECONDS)) {
if(worker.exitValue() != 0) {
throw new RuntimeException("TEST ERROR: subprocess has finished abnormally");
}
System.out.println("TEST PASSED");
return;
} else {
throw new RuntimeException("TEST FAILED: subprocess has not finished for " + TIMEOUT + " sec");
}
}
TestDispose app = new TestDispose();