JBR-6282: java/awt/TextArea/TextAreaEditing/TextAreaEditing.java intermittently fails due to deadlock.

Makes the test invoke any UI-operation on EDT only (since AWT doesn't guarantee thread-safety of UI operations, see more at https://mail.openjdk.org/pipermail/client-libs-dev/2023-November/016172.html).

(cherry picked from commit 8dbb889509)
(cherry picked from commit 559ec0c370)
This commit is contained in:
Nikita Provotorov
2023-11-27 21:17:41 +01:00
committed by jbrbot
parent 7ee101e7e9
commit 3cb15ef9c5

View File

@@ -34,37 +34,43 @@
import java.awt.Frame;
import java.awt.Robot;
import java.awt.TextArea;
import java.awt.AWTException;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import test.java.awt.regtesthelpers.Util;
import javax.swing.*;
public class TextAreaEditing {
final static Robot robot = Util.createRobot();
private int testFailCount;
private boolean isTestFail;
private StringBuilder testFailMessage;
private volatile int testFailCount = 0;
private volatile boolean isTestFail = false;
private final StringBuilder testFailMessage = new StringBuilder();
private Frame mainFrame;
private TextArea textArea;
private Frame mainFrame = null;
private TextArea textArea = null;
private TextAreaEditing() {
testFailMessage = new StringBuilder();
private TextAreaEditing() throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
mainFrame = new Frame();
mainFrame.setSize(200, 200);
textArea = new TextArea();
mainFrame.add(textArea);
mainFrame.setVisible(true);
});
}
private void dispose() {
private void dispose() throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
if (mainFrame != null) {
mainFrame.dispose();
}
});
}
public static void main(String[] s) {
public static void main(String[] s) throws InterruptedException, InvocationTargetException {
TextAreaEditing textArea = new TextAreaEditing();
textArea.testReplaceRange();
textArea.testInsert();
@@ -74,7 +80,8 @@ public class TextAreaEditing {
textArea.dispose();
}
private void testReplaceRange() {
private void testReplaceRange() throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
textArea.setText(null);
textArea.replaceRange("Replace", 0, 0);
textArea.setText(null);
@@ -93,9 +100,11 @@ public class TextAreaEditing {
textArea.replaceRange("replaceRange", 0, textArea.getText().length());
checkTest("replaceRange");
});
}
private void testInsert() {
private void testInsert() throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
textArea.setText(null);
textArea.insert("Insert", 0);
textArea.setText("");
@@ -110,9 +119,11 @@ public class TextAreaEditing {
textArea.insert("Insert", textArea.getText().length());
checkTest("InsertSetInsertTextInsert");
});
}
private void testAppend() {
private void testAppend() throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
textArea.setText(null);
textArea.append("Append");
textArea.setText(null);
@@ -126,27 +137,33 @@ public class TextAreaEditing {
checkTest("SetTextAppend");
textArea.setText("");
checkTest("");
});
}
private void testSetText() {
private void testSetText() throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(() -> {
textArea.setText(null);
textArea.requestFocus();
});
Util.clickOnComp(textArea, robot);
Util.waitForIdle(robot);
robot.keyPress(KeyEvent.VK_A);
robot.delay(5);
robot.keyRelease(KeyEvent.VK_A);
Util.waitForIdle(robot);
SwingUtilities.invokeAndWait(() -> {
textArea.setText(null);
checkTest("");
textArea.setText("CaseSensitive");
checkTest("CaseSensitive");
textArea.setText("caseSensitive");
checkTest("caseSensitive");
});
}
private void checkTest(String str) {
assert SwingUtilities.isEventDispatchThread();
if (str != null && !str.equals(textArea.getText())) {
testFailMessage.append("TestFail line : ");
testFailMessage.append(Thread.currentThread().getStackTrace()[2].
@@ -161,7 +178,7 @@ public class TextAreaEditing {
}
}
private void checkFailures() {
private void checkFailures() throws InterruptedException, InvocationTargetException {
if (isTestFail) {
testFailMessage.insert(0, "Test Fail count : " + testFailCount
+ System.getProperty("line.separator"));