Skip to content

Commit

Permalink
Better synchronization for mojo model update
Browse files Browse the repository at this point in the history
On previous solution code flow could squeeze between conditions of queue and running update, but now we are done only after we done.

Fixup for b6c80a2
  • Loading branch information
hurricup committed Aug 17, 2024
1 parent 6aa0ece commit 4088898
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.jetbrains.annotations.TestOnly;

import java.util.*;
import com.intellij.util.concurrency.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;

Expand All @@ -56,6 +57,7 @@ public class MojoProjectManager implements Disposable {
private final @NotNull MergingUpdateQueue myUpdateQueue;
private final @NotNull AtomicBoolean myUpdatingModel = new AtomicBoolean(false);
private volatile @NotNull Model myModel = new Model(Collections.emptySet());
private volatile Semaphore myTestSemaphore;

public MojoProjectManager(@NotNull Project project) {
myProject = project;
Expand Down Expand Up @@ -140,7 +142,16 @@ private void updateModel() {
scheduleUpdate();
}
else {
doUpdateModel();
try{
LOG.debug("Performing model update");
doUpdateModel();
}
finally {
if( myTestSemaphore != null) {
myTestSemaphore.up();
myTestSemaphore = null;
}
}
}
});
}
Expand Down Expand Up @@ -281,7 +292,9 @@ private Set<MojoProject> getProjects() {

@TestOnly
public BooleanSupplier updateInTestMode() {
var semaphore = new Semaphore(1);
myTestSemaphore = semaphore;
updateModel();
return ()-> myUpdateQueue.isEmpty() && !myUpdatingModel.get();
return semaphore::isUp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import java.util.function.BooleanSupplier;
import java.util.function.Function;

@Category(Integration.class)
@RunWith(Parameterized.class)
public abstract class PerlPlatformTestCase extends HeavyPlatformTestCase {
private static final int MAX_PROCESS_WAIT_TIME_SECONDS = 120;
Expand Down

0 comments on commit 4088898

Please sign in to comment.