Skip to content

Commit

Permalink
Bug 526917 - waitForAutoBuild to fix OpenFromClipboardTests eclipse-j…
Browse files Browse the repository at this point in the history
…dt#28

OpenFromClipboardTests can not use TestAgainException because it does
not extend AbstractDebugTest to actually use the
retry logic also a retry does not in this test.

eclipse-jdt#28
  • Loading branch information
EcljpseB0T committed Dec 4, 2023
1 parent 6665a8e commit 82eafb8
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;

Expand Down Expand Up @@ -67,6 +69,16 @@ public static void enableAutobuild(boolean enable) throws CoreException {
IWorkspaceDescription desc= workspace.getDescription();
desc.setAutoBuilding(enable);
workspace.setDescription(desc);
waitForAutoBuild();
}

private static void waitForAutoBuild() {
Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_BUILD);
try {
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;
import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
import org.eclipse.jface.preference.IPreferenceStore;
Expand Down Expand Up @@ -57,10 +56,7 @@ public void testSimpleStepFilter() throws Exception {
thread = stepIntoWithFilters(stackFrame);
stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
String recTypeName = stackFrame.getReceivingTypeName();
if (!"StepFilterOne".equals(recTypeName)) {
throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne"); // @see bug 297071
}
assertEquals("Wrong receiving type", "StepFilterOne", recTypeName);
tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName));
int lineNumber = stackFrame.getLineNumber();
assertEquals("Wrong line number", 27, lineNumber);
} finally {
Expand All @@ -86,10 +82,7 @@ public void testDontStepThruStepFilters() throws Exception {
thread = stepIntoWithFilters(stackFrame, false);
stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
String recTypeName = stackFrame.getReceivingTypeName();
if (!"StepFilterOne".equals(recTypeName)) {
throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne"); // @see bug 297071
}
assertEquals("Wrong receiving type", "StepFilterOne", recTypeName);
tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName));
int lineNumber = stackFrame.getLineNumber();
assertEquals("Wrong line number", 28, lineNumber);
} finally {
Expand All @@ -115,10 +108,7 @@ public void testInactiveStepFilter() throws Exception {
thread = stepIntoWithFilters(stackFrame);
stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
String recTypeName = stackFrame.getReceivingTypeName();
if (!"StepFilterTwo".equals(recTypeName)) {
throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterTwo"); // @see bug 297071
}
assertEquals("Wrong receiving type", "StepFilterTwo", recTypeName);
tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterTwo", recTypeName));
int lineNumber = stackFrame.getLineNumber();
assertEquals("Wrong line number", 28, lineNumber);
} finally {
Expand All @@ -145,10 +135,7 @@ public void testDeepStepFilter() throws Exception {
thread = stepIntoWithFilters(stackFrame);
stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
String recTypeName = stackFrame.getReceivingTypeName();
if (!"StepFilterThree".equals(recTypeName)) {
throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterThree");
}
assertEquals("Wrong receiving type", "StepFilterThree", recTypeName);
tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterThree", recTypeName));
int lineNumber = stackFrame.getLineNumber();
assertEquals("Wrong line number", 22, lineNumber);
} finally {
Expand All @@ -174,10 +161,7 @@ public void testStepReturnFilter() throws Exception {
thread = stepReturnWithFilters(stackFrame);
stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
String recTypeName = stackFrame.getReceivingTypeName();
if (!"StepFilterOne".equals(recTypeName)) {
throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne");
}
assertEquals("Wrong receiving type", "StepFilterOne", recTypeName);
tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName));
int lineNumber = stackFrame.getLineNumber();
assertEquals("Wrong line number", 26, lineNumber);
} finally {
Expand All @@ -203,10 +187,7 @@ public void testStepOverFilter() throws Exception {
thread = stepOverWithFilters(stackFrame);
stackFrame = (IJavaStackFrame) thread.getTopStackFrame();
String recTypeName = stackFrame.getReceivingTypeName();
if (!"StepFilterOne".equals(recTypeName)) {
throw new TestAgainException("Retest - "+recTypeName+" is does not match StepFilterOne");
}
assertEquals("Wrong receiving type", "StepFilterOne", recTypeName);
tryAgain(() -> assertEquals("Wrong receiving type", "StepFilterOne", recTypeName));
int lineNumber = stackFrame.getLineNumber();
assertEquals("Wrong line number", 26, lineNumber);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ synchronized void assert16_Project() {
handleProjectCreationException(e, ONESIX_PROJECT_NAME, jp);
}
}

/**
* Creates the Java 21 compliant project
*/
Expand Down Expand Up @@ -895,7 +895,7 @@ protected IJavaProject get9Project() {
assert9Project();
return getJavaProject(NINE_PROJECT_NAME);
}

/**
* Returns the 'Two_One' project, used for Java 21 tests.
*
Expand Down Expand Up @@ -2293,10 +2293,7 @@ protected IEvaluationResult evaluate(String snippet, IJavaStackFrame frame) thro

Object suspendee= waiter.waitForEvent();
setEventSet(waiter.getEventSet());
if(suspendee == null) {
throw new TestAgainException("Program did not suspend evaluating: \n\n"+snippet);
}
assertNotNull("Program did not suspend.", suspendee); //$NON-NLS-1$
tryAgain(() -> assertNotNull("Program did not suspend evaluating: \n\n" + snippet, suspendee)); //$NON-NLS-1$
return fEvaluationResult;
}
finally {
Expand Down Expand Up @@ -2666,8 +2663,32 @@ private void setEnvironment(ILaunchConfigurationWorkingCopy workingCopy) {
workingCopy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, env);
}

/**
* Exception to indicate a test should be run again when it fails.
*/
protected static class TestAgainException extends RuntimeException {
private static final long serialVersionUID = 1848804390493463729L;

public TestAgainException(String string) {
super(string);
}

public TestAgainException(Throwable cause) {
super("Try test again because of random fail.", cause);
}
}

protected void tryAgain(Runnable run) {
try {
run.run();
} catch (AssertionError e) {
throw new TestAgainException(e);
}
}

/**
* When a test throws the 'try again' exception, try it again.
*
* @see junit.framework.TestCase#runBare()
*/
@Override
Expand Down Expand Up @@ -2740,7 +2761,7 @@ protected void tryTestAgain(DebugException e) throws Exception {
if (cause instanceof InternalException) {
int code = ((InternalException)cause).errorCode();
if (code == 13) {
throw new TestAgainException("Retest - exception during test: "+getName()+": "+e.getMessage());
throw new TestAgainException(e);
}
}
throw e;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.jdt.debug.eval.IEvaluationListener;
import org.eclipse.jdt.debug.eval.IEvaluationResult;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;
import org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine;
import org.eclipse.jdt.internal.debug.ui.threadgroups.JavaDebugTargetProxy;
import org.eclipse.jdt.internal.debug.ui.threadgroups.JavaThreadEventHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.jdt.debug.testplugin.DebugElementKindEventDetailWaiter;
import org.eclipse.jdt.debug.testplugin.DebugEventWaiter;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;
import org.eclipse.jdt.internal.debug.core.JavaDebugUtils;
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint;
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaClassPrepareBreakpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.jdt.debug.core.IJavaWatchpoint;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;

/**
* Tests watchpoint, both modification and access watchpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.jdt.debug.testplugin.DebugElementEventWaiter;
import org.eclipse.jdt.debug.testplugin.DebugEventWaiter;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;

/**
* Tests hot code replace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.jdt.debug.core.IJavaVariable;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;
import org.eclipse.jdt.internal.debug.core.model.JDIArrayValue;
import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable;
import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.TypeNameRequestor;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.debug.tests.TestAgainException;
import org.eclipse.ltk.core.refactoring.CheckConditionsOperation;
import org.eclipse.ltk.core.refactoring.PerformRefactoringOperation;
import org.eclipse.ltk.core.refactoring.Refactoring;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.jdt.debug.core.IJavaThread;
import org.eclipse.jdt.debug.testplugin.DebugElementKindEventDetailWaiter;
import org.eclipse.jdt.debug.testplugin.DebugEventWaiter;
import org.eclipse.jdt.debug.tests.TestAgainException;
import org.eclipse.jdt.debug.tests.TestUtil;
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
import org.eclipse.jdt.internal.debug.core.model.JDIStackFrame;
Expand Down
Loading

0 comments on commit 82eafb8

Please sign in to comment.