flaky test fixed

This commit is contained in:
Alexey Kudravtsev
2017-02-13 14:36:50 +03:00
parent 18e7fa5d74
commit 483862b5fa
3 changed files with 11 additions and 12 deletions
@@ -96,7 +96,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ApplicationImpl extends PlatformComponentManagerImpl implements ApplicationEx {
private static final Logger LOG = Logger.getInstance("#com.intellij.application.impl.ApplicationImpl");
private final ReadMostlyRWLock myLock;
final ReadMostlyRWLock myLock;
private final ModalityInvokator myInvokator = new ModalityInvokatorImpl();
@@ -110,7 +110,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
private final String myName;
private final Stack<Class> myWriteActionsStack = new Stack<>(); // accessed from EDT only, no need to sync
private int myWriteStackBase = 0;
private int myWriteStackBase;
private volatile Thread myWriteActionThread;
private int myInEditorPaintCounter; // EDT only
@@ -163,7 +163,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
AWTExceptionHandler.register(); // do not crash AWT on exceptions
Disposer.setDebugMode((isInternal || isUnitTestMode || Disposer.isDebugDisposerOn()));
Disposer.setDebugMode(isInternal || isUnitTestMode || Disposer.isDebugDisposerOn());
myStartTime = System.currentTimeMillis();
mySplash = splash;
@@ -487,7 +487,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
@Override
protected void setProgressDuringInit(@NotNull ProgressIndicator indicator) {
float start = PluginManagerCore.PLUGINS_PROGRESS_PART + PluginManagerCore.LOADERS_PROGRESS_PART;
indicator.setFraction(start + (getPercentageOfComponentsLoaded() * (1 - start)));
indicator.setFraction(start + getPercentageOfComponentsLoaded() * (1 - start));
}
private static void createLocatorFile() {
@@ -1187,11 +1187,10 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App
if (!myLock.isWriteLocked()) {
assertNoPsiLock();
if (!myLock.tryWriteLock()) {
Future<?> reportSlowWrite = ourDumpThreadsOnLongWriteActionWaiting > 0 ?
JobScheduler.getScheduler()
.scheduleWithFixedDelay(() -> PerformanceWatcher.getInstance().dumpThreads("waiting", true),
ourDumpThreadsOnLongWriteActionWaiting,
ourDumpThreadsOnLongWriteActionWaiting, TimeUnit.MILLISECONDS) : null;
Future<?> reportSlowWrite = ourDumpThreadsOnLongWriteActionWaiting <= 0 ? null :
JobScheduler.getScheduler().scheduleWithFixedDelay(() -> PerformanceWatcher.getInstance().dumpThreads("waiting", true),
ourDumpThreadsOnLongWriteActionWaiting,
ourDumpThreadsOnLongWriteActionWaiting, TimeUnit.MILLISECONDS);
myLock.writeLock();
if (reportSlowWrite != null) {
reportSlowWrite.cancel(false);
@@ -48,7 +48,7 @@ import java.util.concurrent.locks.LockSupport;
class ReadMostlyRWLock {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.application.impl.ReadMostlyRWLock");
private final Thread writeThread;
private volatile boolean writeRequested; // this writer is requesting or obtained the write access
volatile boolean writeRequested; // this writer is requesting or obtained the write access
private volatile boolean writeAcquired; // this writer obtained the write lock
// All reader threads are registered here. Dead readers are garbage collected in writeUnlock().
private final ConcurrentList<Reader> readers = ContainerUtil.createConcurrentList();
@@ -693,8 +693,8 @@ public class ApplicationImplTest extends LightPlatformTestCase {
);
while (!readAcquired.get());
Future<?> readAction2 = app.executeOnPooledThread(() -> {
// wait for write action attempt to start
while (!app.isWriteActionPending());
// wait for write action attempt to start - i.e. app.myLock.writeLock() started to execute
while (!app.myLock.writeRequested);
app.executeByImpatientReader(() -> {
try {
app.runReadAction(EmptyRunnable.getInstance());