public static void invokeAndWaitWriteAction(@NotNull Project p, @NotNull Runnable r) {
    startTestRunnable(r);
    if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
      runAndFinishTestRunnable(r);
    }
    else if (ApplicationManager.getApplication().isDispatchThread()) {
      ApplicationManager.getApplication().runWriteAction(r);
    }
    else {
      ApplicationManager.getApplication().invokeAndWait(DisposeAwareRunnable.create(
                                                          () -> ApplicationManager.getApplication().runWriteAction(() -> runAndFinishTestRunnable(r)), p),
                                                        ModalityState.defaultModalityState());
    }
  }
public static void invokeAndWaitWriteAction(@NotNull Project p, @NotNull Runnable r)