|
19 | 19 | import static org.junit.Assert.assertNotNull; |
20 | 20 | import static org.junit.Assert.assertTrue; |
21 | 21 |
|
| 22 | +import com.google.cloud.tools.eclipse.test.util.reflection.ReflectionUtil; |
22 | 23 | import com.google.common.base.Joiner; |
23 | 24 | import com.google.common.base.Stopwatch; |
24 | 25 | import java.io.File; |
|
35 | 36 | import java.util.concurrent.TimeUnit; |
36 | 37 | import java.util.zip.ZipEntry; |
37 | 38 | import java.util.zip.ZipFile; |
| 39 | +import org.eclipse.core.internal.jobs.InternalJob; |
38 | 40 | import org.eclipse.core.resources.IMarker; |
39 | 41 | import org.eclipse.core.resources.IProject; |
40 | 42 | import org.eclipse.core.resources.IProjectDescription; |
@@ -227,20 +229,55 @@ public static void waitForProjects(Runnable delayTactic, IProject... projects) { |
227 | 229 | timer, currentBuildErrors.size()); |
228 | 230 | } |
229 | 231 | // Uncomment if tests are failing to identify any other build-related jobs. |
230 | | - Job[] otherJobs = Job.getJobManager().find(null); |
231 | | - if (otherJobs.length > 0) { |
232 | | - System.err.printf("Ignoring %d unrelated jobs:\n", otherJobs.length); |
233 | | - for (Job job : otherJobs) { |
234 | | - System.err.printf(" %s: %s\n", job.getClass().getName(), job); |
235 | | - } |
236 | | - } |
| 232 | + dumpJobsState(); |
237 | 233 | } |
238 | 234 | } while (!jobs.isEmpty() || buildErrorsChanging); |
239 | 235 | } catch (CoreException | InterruptedException ex) { |
240 | 236 | throw new RuntimeException(ex); |
241 | 237 | } |
242 | 238 | } |
243 | 239 |
|
| 240 | + private static void dumpJobsState() { |
| 241 | + Job[] otherJobs = Job.getJobManager().find(null); |
| 242 | + if (otherJobs.length == 0) { |
| 243 | + System.err.printf("ProjectUtils#dumpJobsState: no jobs\n"); |
| 244 | + return; |
| 245 | + } |
| 246 | + |
| 247 | + System.err.printf("ProjectUtils#dumpJobsState: %d jobs:\n", otherJobs.length); |
| 248 | + for (Job job : otherJobs) { |
| 249 | + String status; |
| 250 | + switch (job.getState()) { |
| 251 | + case Job.RUNNING: |
| 252 | + status = "RUNNING"; |
| 253 | + break; |
| 254 | + case Job.WAITING: |
| 255 | + status = "WAITING"; |
| 256 | + break; |
| 257 | + case Job.SLEEPING: |
| 258 | + status = "SLEEPING"; |
| 259 | + break; |
| 260 | + case Job.NONE: |
| 261 | + status = "NONE"; |
| 262 | + break; |
| 263 | + default: |
| 264 | + status = "UNKNOWN(" + job.getState() + ")"; |
| 265 | + break; |
| 266 | + } |
| 267 | + Object blockingJob = null; |
| 268 | + try { |
| 269 | + blockingJob = |
| 270 | + ReflectionUtil.invoke(Job.getJobManager(), "findBlockingJob", InternalJob.class, job); |
| 271 | + } catch (Exception ex) { |
| 272 | + System.err.println("Unable to fetch blocking-job: " + ex); |
| 273 | + } |
| 274 | + System.err.printf(" %s[%d,%s%s%s%s]: %s%s\n", job.getClass().getName(), job.getPriority(), |
| 275 | + status, (job.isUser() ? ",user" : ""), (job.isSystem() ? ",system" : ""), |
| 276 | + (job.isBlocking() ? ",blocking" : ""), job, |
| 277 | + (blockingJob != null ? "; blocked by: " + blockingJob : "")); |
| 278 | + } |
| 279 | + } |
| 280 | + |
244 | 281 | /** Identify all jobs that we know of that are related to building. */ |
245 | 282 | private static Collection<Job> findPendingBuildJobs(IProject... projects) { |
246 | 283 | Set<Job> jobs = new HashSet<>(); |
|
0 commit comments