remember background vfs refresh start trace in tests

to diagnose flaky "PSI/document/model changes are not allowed during highlighting"
This commit is contained in:
peter
2016-12-02 15:57:32 +01:00
parent 8849cfcab6
commit 4257264826
2 changed files with 17 additions and 6 deletions
@@ -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<Document,FileStatus> 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
@@ -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<VFileEvent> 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);