Skip to content

Commit

Permalink
Properly update names cache from the pooled thread
Browse files Browse the repository at this point in the history
Not sure how this did work previously. But we requested read action in smart mode from edt, and if we were in the dumb mode, this should have locked, because we are blocking edt and it is necessary to leave the dumb mode.
  • Loading branch information
hurricup committed Nov 13, 2024
1 parent eeb1e75 commit b6a5212
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mojo/src/test/java/completion/MojoCompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MojoCompletionTest extends MojoLightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
updateNamesCacheSynchronously();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion mojo/src/test/java/completion/MojoPerlCompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class MojoPerlCompletionTest extends MojoLightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
updateNamesCacheSynchronously();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void doUpdateCache() {

public void forceCacheUpdate() {
var application = ApplicationManager.getApplication();
LOG.assertTrue(!application.isDispatchThread() || application.isUnitTestMode());
application.assertIsNonDispatchThread();
doUpdateCache();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class PerlCompletionTestCase extends PerlLightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
updateNamesCacheSynchronously();
myState = CodeInsightSettings.getInstance().getState();
disableAutoInsertion();
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/test/java/completion/PerlPMCompletionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PerlPMCompletionTest extends PerlLightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
updateNamesCacheSynchronously();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PodCompletionEmbeddedTest extends PerlLightTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
updateNamesCacheSynchronously();
}

@Override
Expand Down
21 changes: 17 additions & 4 deletions plugin/src/testFixtures/java/base/PerlLightTestCaseBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
Expand Down Expand Up @@ -418,8 +419,8 @@ protected void addTestLibrary(@NotNull String testLibraryName) {
perlProjectManager.addExternalLibrary(libdir);

CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject());
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
}));
updateNamesCacheSynchronously();
}

/**
Expand Down Expand Up @@ -464,9 +465,21 @@ protected void setUpLibrary() {
PerlSdkTable.getInstance().addJdk(testSdk, myPerlLightTestCaseDisposable);
perlProjectManager.setProjectSdk(testSdk);
perlProjectManager.addExternalLibrary(libdir);
CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject());
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
}));
updateNamesCacheSynchronously();
}

protected final void updateNamesCacheSynchronously() {
var app = ApplicationManager.getApplication();
app.invokeAndWait(() -> CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()));
if (app.isDispatchThread()) {
Future<?> namesUpdate =
app.executeOnPooledThread(() -> PerlNamesCache.getInstance(getProject()).forceCacheUpdate());
PlatformTestUtil.waitWithEventsDispatching("Unable to update names in 5 seconds", namesUpdate::isDone, 5);
}
else {
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
}
}

protected @NotNull String getTestLibPath() {
Expand Down Expand Up @@ -847,7 +860,7 @@ public void doTestResolve(boolean reparse) {

public void doTestResolveWithoutInit(boolean reparse) {
if (reparse) {
PerlNamesCache.getInstance(getProject()).forceCacheUpdate();
updateNamesCacheSynchronously();
FileContentUtil.reparseFiles(getProject(), Collections.emptyList(), true);
}
checkSerializedReferencesWithFile();
Expand Down

0 comments on commit b6a5212

Please sign in to comment.