From 4257264826a95a03a7848dd2afafef6bf0961d98 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 2 Dec 2016 15:10:08 +0100 Subject: [PATCH] remember background vfs refresh start trace in tests to diagnose flaky "PSI/document/model changes are not allowed during highlighting" --- .../daemon/impl/FileStatusMap.java | 4 +++- .../vfs/newvfs/RefreshSessionImpl.java | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java index bca837742ed3..1b20d204087f 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/FileStatusMap.java @@ -46,6 +46,8 @@ import java.util.concurrent.ConcurrentMap; public class FileStatusMap implements Disposable { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.FileStatusMap"); + public static final String CHANGES_NOT_ALLOWED_DURING_HIGHLIGHTING = + "PSI/document/model changes are not allowed during highlighting"; private final Project myProject; private final Map myDocumentToStatusMap = new WeakHashMap<>(); // all dirty if absent private volatile boolean myAllowDirt = true; @@ -170,7 +172,7 @@ public class FileStatusMap implements Disposable { private void assertAllowModifications() { try { - assert myAllowDirt : "PSI/document/model changes are not allowed during highlighting"; + assert myAllowDirt : CHANGES_NOT_ALLOWED_DURING_HIGHLIGHTING; } finally { myAllowDirt = true; //give next test a chance diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java index 285b077b4ed5..73f55d98c98c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshSessionImpl.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.vfs.newvfs; +import com.intellij.codeInsight.daemon.impl.FileStatusMap; import com.intellij.openapi.application.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.DumbServiceImpl; @@ -63,13 +64,15 @@ public class RefreshSessionImpl extends RefreshSession { myModalityState = modalityState; myTransaction = ((TransactionGuardImpl)TransactionGuard.getInstance()).getModalityTransaction(modalityState); LOG.assertTrue(modalityState == ModalityState.NON_MODAL || modalityState != ModalityState.any(), "Refresh session should have a specific modality"); + myStartTrace = rememberStartTrace(); + } - if (modalityState == ModalityState.NON_MODAL) { - myStartTrace = null; - } - else { - myStartTrace = new Throwable(); // please report exceptions here to peter + private Throwable rememberStartTrace() { + if (ApplicationManager.getApplication().isUnitTestMode() && + (myIsAsync || !ApplicationManager.getApplication().isDispatchThread())) { + return new Throwable(); } + return myModalityState == ModalityState.NON_MODAL ? null : new Throwable(); } public RefreshSessionImpl(@NotNull List events) { @@ -194,6 +197,12 @@ public class RefreshSessionImpl extends RefreshSession { scan(); } } + catch (AssertionError e) { + if (FileStatusMap.CHANGES_NOT_ALLOWED_DURING_HIGHLIGHTING.equals(e.getMessage())) { + throw new AssertionError("VFS changes are not allowed during highlighting", myStartTrace); + } + throw e; + } finally { try { manager.fireAfterRefreshFinish(myIsAsync);