コード例 #1
0
 protected void runBareRunnable(ThrowableRunnable<Throwable> runnable) throws Throwable {
   if (isRunInEdt()) {
     EdtTestUtil.runInEdtAndWait(runnable);
   } else {
     runnable.run();
   }
 }
コード例 #2
0
 @TestOnly
 public static <T extends Throwable> void runWithDisabledPreview(ThrowableRunnable<T> runnable)
     throws T {
   PREVIEW_IN_TESTS = false;
   try {
     runnable.run();
   } finally {
     PREVIEW_IN_TESTS = true;
   }
 }
コード例 #3
0
  private static void doWithAltClickShortcut(ThrowableRunnable runnable) throws Throwable {
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    MouseShortcut shortcut = new MouseShortcut(1, InputEvent.ALT_DOWN_MASK, 1);
    try {
      keymap.addShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut);

      runnable.run();
    } finally {
      keymap.removeShortcut(IdeActions.ACTION_EDITOR_ADD_OR_REMOVE_CARET, shortcut);
    }
  }
 @Override
 protected void runBareRunnable(ThrowableRunnable<Throwable> r) throws Throwable {
   if (getName().equals("testRefreshingAsynchronously")) {
     // this method waits for another thread to finish, that leads
     // to deadlock in swing-thread. Therefore we have to run this test
     // outside of swing-thread
     r.run();
   } else {
     super.runBareRunnable(r);
   }
 }
コード例 #5
0
 private static void doClear(
     ThrowableRunnable<StorageException> clearAction, AtomicReference<RebuildStatus> status)
     throws StorageException {
   try {
     clearAction.run();
   } catch (StorageException e) {
     status.compareAndSet(DOING_REBUILD, REQUIRES_REBUILD);
     throw e;
   }
   if (!status.compareAndSet(DOING_REBUILD, OK)) {
     FileBasedIndexImpl.LOG.error("Unexpected status " + status.get());
   }
 }
コード例 #6
0
 public static void withEncoding(@NotNull String encoding, @NotNull ThrowableRunnable r) {
   Charset oldCharset = Charset.defaultCharset();
   try {
     try {
       patchSystemFileEncoding(encoding);
       r.run();
     } finally {
       patchSystemFileEncoding(oldCharset.name());
     }
   } catch (Throwable t) {
     throw new RuntimeException(t);
   }
 }
コード例 #7
0
 @Override
 protected void runBareRunnable(ThrowableRunnable<Throwable> runnable) throws Throwable {
   runnable.run();
 }
コード例 #8
0
    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;
      }
    }