Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to get OpenFromClipboardTests.testMethod_11 stable #446

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.eclipse.jdt.debug.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.debug.tests; singleton:=true
Bundle-Version: 3.12.400.qualifier
Bundle-Version: 3.12.500.qualifier
Bundle-ClassPath: javadebugtests.jar
Bundle-Activator: org.eclipse.jdt.debug.testplugin.JavaTestPlugin
Bundle-Vendor: %providerName
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.debug.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.debug.tests</artifactId>
<version>3.12.400-SNAPSHOT</version>
<version>3.12.500-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import org.eclipse.core.internal.jobs.JobManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
Expand Down Expand Up @@ -133,12 +134,16 @@ public static boolean waitForJobs(String owner, long minTimeMs, long maxTimeMs)
* @return true if the method timed out, false if all the jobs terminated before the timeout
*/
public static boolean waitForJobs(String owner, long minTimeMs, long maxTimeMs, Object... excludedFamilies) {
return waitForJobs(owner, null, minTimeMs, maxTimeMs, excludedFamilies);
}

public static boolean waitForJobs(@SuppressWarnings("unused") String owner, Object jobFamily, long minTimeMs, long maxTimeMs, Object... excludedFamilies) {
if (maxTimeMs < minTimeMs) {
throw new IllegalArgumentException("Max time is smaller as min time!");
}
wakeUpSleepingJobs(null);
final long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < minTimeMs) {
wakeUpSleepingJobs(jobFamily);
final long start = System.nanoTime();
while (System.nanoTime() - start < minTimeMs * 1_000_000) {
runEventLoop();
try {
Thread.sleep(Math.min(10, minTimeMs));
Expand All @@ -147,29 +152,28 @@ public static boolean waitForJobs(String owner, long minTimeMs, long maxTimeMs,
}
}
while (!Job.getJobManager().isIdle()) {
runEventLoop();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// Uninterruptable
}
List<Job> jobs = getRunningOrWaitingJobs(null, excludedFamilies);
List<Job> jobs = getRunningOrWaitingJobs(jobFamily, excludedFamilies);
if (jobs.isEmpty()) {
// only uninteresting jobs running
break;
}

if (!Collections.disjoint(runningJobs, jobs)) {
// There is a job which runs already quite some time, don't wait for it to avoid test timeouts
dumpRunningOrWaitingJobs(owner, jobs);
dumpRunningOrWaitingJobs(jobs);
return true;
}

if (System.currentTimeMillis() - start >= maxTimeMs) {
dumpRunningOrWaitingJobs(owner, jobs);
if (System.nanoTime() - start >= maxTimeMs * 1_000_000) {
dumpRunningOrWaitingJobs(jobs);
return true;
}
wakeUpSleepingJobs(null);
wakeUpSleepingJobs(jobFamily);
runEventLoop();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// Uninterruptable
}
}
runningJobs.clear();
return false;
Expand All @@ -184,12 +188,12 @@ private static void wakeUpSleepingJobs(Object family) {

static Set<Job> runningJobs = new LinkedHashSet<>();

private static void dumpRunningOrWaitingJobs(String owner, List<Job> jobs) {
String message = "Some job is still running or waiting to run: " + dumpRunningOrWaitingJobs(jobs);
log(IStatus.ERROR, owner, message);
private static void dumpRunningOrWaitingJobs(List<Job> jobs) {
new IllegalStateException("Some job is still running or waiting to run.").printStackTrace();
System.err.println("JobList:" + getDump(jobs));
}

private static String dumpRunningOrWaitingJobs(List<Job> jobs) {
private static String getDump(List<Job> jobs) {
if (jobs.isEmpty()) {
return "";
}
Expand All @@ -200,6 +204,7 @@ private static String dumpRunningOrWaitingJobs(List<Job> jobs) {
runningJobs.add(job);
sb.append("\n'").append(job.toString()).append("'/");
sb.append(job.getClass().getName());
sb.append(":").append(JobManager.printState(job));
Thread thread = job.getThread();
if (thread != null) {
ThreadInfo[] threadInfos = ManagementFactory.getThreadMXBean().getThreadInfo(new long[] { thread.getId() }, true, true);
Expand All @@ -212,7 +217,7 @@ private static String dumpRunningOrWaitingJobs(List<Job> jobs) {

Thread thread = Display.getDefault().getThread();
ThreadInfo[] threadInfos = ManagementFactory.getThreadMXBean().getThreadInfo(new long[] { thread.getId() }, true, true);
if (threadInfos[0] != null) {
if (!Thread.currentThread().equals(thread) && threadInfos[0] != null) {
sb.append("\n").append("UI thread info: ").append(threadInfos[0]);
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.eclipse.core.internal.resources.CharsetDeltaJob;
import org.eclipse.core.internal.resources.ValidateProjectEncoding;
Expand Down Expand Up @@ -97,8 +97,8 @@ public static void tearDownClass() throws CoreException {
}

private static void waitForEncodingRelatedJobs() {
TestUtil.waitForJobs("OpenFromClipboardTests", 10, 5_000, ValidateProjectEncoding.class);
TestUtil.waitForJobs("OpenFromClipboardTests", 10, 5_000, CharsetDeltaJob.FAMILY_CHARSET_DELTA);
TestUtil.waitForJobs("OpenFromClipboardTests", ValidateProjectEncoding.class, 0, 5_000);
TestUtil.waitForJobs("OpenFromClipboardTests", CharsetDeltaJob.FAMILY_CHARSET_DELTA, 0, 5_000);
}

private static IJavaProject createProject(String name) throws CoreException {
Expand Down Expand Up @@ -136,7 +136,7 @@ private int getMatachingPattern(String s) throws Exception {

private List<?> getJavaElementMatches(final String textData) throws Exception {
JavaModelManager.getIndexManager().waitForIndex(false, null);
final List<Object> matches = new ArrayList<>();
final List<Object> matches = new CopyOnWriteArrayList<>();
Display.getDefault().syncCall(() -> OpenFromClipboardAction.getJavaElementMatches(textData, matches));
return matches;
}
Expand Down
Loading