void () { int N = 10_000; List<Integer> things = new ArrayList<>(N); int sum = 0; for (int i = 0; i < N; i++) { int v = i < N-50 ? 1 : 1000; things.add(v); sum += v; } //noinspection PointlessArithmeticExpression assertEquals((N-50)*1 + 50*1000, sum); long elapsed = TimeoutUtil.measureExecutionTime(() -> assertTrue(JobLauncher.getInstance().invokeConcurrentlyUnderProgress(things, new ProgressIndicatorBase(), o -> { if (o <= 1) { busySleepAndIncrement(o); } else { longSleep(o); } return true; }))); long expected = sum / JobSchedulerImpl.getJobPoolParallelism(); String message = "Elapsed: " + elapsed + "; expected: " + expected + "; parallelism=" + JobSchedulerImpl.getJobPoolParallelism() + "; current cores=" + Runtime.getRuntime().availableProcessors(); assertTrue(message, elapsed <= 2 * expected); }