public void assertTiming() { assert expectedMs != 0 : "Must call .expect() before run test"; if (COVERAGE_ENABLED_BUILD) return; while (true) { attempts--; long start; try { if (setup != null) setup.run(); start = System.currentTimeMillis(); test.run(); } catch (Throwable throwable) { throw new RuntimeException(throwable); } long finish = System.currentTimeMillis(); long duration = finish - start; int expectedOnMyMachine = expectedMs; if (adjustForCPU) { expectedOnMyMachine = adjust(expectedOnMyMachine, Timings.CPU_TIMING, Timings.ETALON_CPU_TIMING); expectedOnMyMachine = usesAllCPUCores ? expectedOnMyMachine * 8 / JobSchedulerImpl.CORES_COUNT : expectedOnMyMachine; } if (adjustForIO) { expectedOnMyMachine = adjust(expectedOnMyMachine, Timings.IO_TIMING, Timings.ETALON_IO_TIMING); } // Allow 10% more in case of test machine is busy. String logMessage = message; if (duration > expectedOnMyMachine) { int percentage = (int) (100.0 * (duration - expectedOnMyMachine) / expectedOnMyMachine); logMessage += ": " + percentage + "% longer"; } logMessage += ". Expected: " + formatTime(expectedOnMyMachine) + ". Actual: " + formatTime(duration) + "." + Timings.getStatistics(); final double acceptableChangeFactor = 1.1; if (duration < expectedOnMyMachine) { int percentage = (int) (100.0 * (expectedOnMyMachine - duration) / expectedOnMyMachine); logMessage = percentage + "% faster. " + logMessage; TeamCityLogger.info(logMessage); System.out.println("SUCCESS: " + logMessage); } else if (duration < expectedOnMyMachine * acceptableChangeFactor) { TeamCityLogger.warning(logMessage, null); System.out.println("WARNING: " + logMessage); } else { // try one more time if (attempts == 0) { // try { // Object result = // Class.forName("com.intellij.util.ProfilingUtil").getMethod("captureCPUSnapshot").invoke(null); // System.err.println("CPU snapshot captured in '"+result+"'"); // } // catch (Exception e) { // } throw new AssertionFailedError(logMessage); } System.gc(); System.gc(); System.gc(); String s = "Another epic fail (remaining attempts: " + attempts + "): " + logMessage; TeamCityLogger.warning(s, null); System.err.println(s); // if (attempts == 1) { // try { // // Class.forName("com.intellij.util.ProfilingUtil").getMethod("startCPUProfiling").invoke(null); // } // catch (Exception e) { // } // } continue; } break; } }