join thread in tests to avoid thread leaks

This commit is contained in:
Alexey Kudravtsev
2015-11-13 13:52:35 +03:00
parent 2ba20ccf45
commit 2b999838c8
16 changed files with 218 additions and 269 deletions
@@ -99,7 +99,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
super.tearDown();
}
public void testFindString() {
public void testFindString() throws InterruptedException {
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
String text = "public static class MyClass{\n/*done*/\npublic static void main(){}}";
@@ -149,7 +149,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
findModel.setProjectScope(true);
final FindResult[] findResultArr = new FindResult[1];
findInNewThread(findModel, myFindManager, text, 0, findResultArr);
Thread thread = findInNewThread(findModel, myFindManager, text, 0, findResultArr);
new WaitFor(30 *1000){
@Override
protected boolean condition() {
@@ -158,6 +158,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
}.assertCompleted();
assertFalse(findResultArr[0].isStringFound());
thread.join();
}
private static Thread findInNewThread(final FindModel model,
@@ -110,15 +110,9 @@ public class PsiConcurrencyStressTest extends DaemonAnalyzerTestCase {
}
assertTrue("Timed out", reads.await(5, TimeUnit.MINUTES));
ContainerUtil.process(threads, thread -> {
try {
thread.join();
return true;
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
for (Thread thread : threads) {
thread.join();
}
}
private static void mark(final String s) {
@@ -417,6 +417,7 @@ public class LaterInvocatorTest extends PlatformTestCase {
flushSwingQueue();
checkOrder(1);
});
thread.join();
}
private static void flushSwingQueue() {
@@ -28,9 +28,10 @@ import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
import com.intellij.testFramework.BombedProgressIndicator;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.*;
import com.intellij.util.Alarm;
import com.intellij.util.ArrayUtil;
import com.intellij.util.TimeoutUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.DoubleArrayList;
import com.intellij.util.containers.Stack;
@@ -64,17 +65,14 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
public void testProgressManagerCheckCanceledWorksRightAfterIndicatorBeenCanceled() {
for (int i=0; i<1000;i++) {
final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
ProgressManager.getInstance().runProcess(new Runnable() {
@Override
public void run() {
ProgressManager.getInstance().runProcess(() -> {
ProgressManager.checkCanceled();
try {
indicator.cancel();
ProgressManager.checkCanceled();
try {
indicator.cancel();
ProgressManager.checkCanceled();
fail("checkCanceled() must have caught just canceled indicator");
}
catch (ProcessCanceledException ignored) {
}
fail("checkCanceled() must have caught just canceled indicator");
}
catch (ProcessCanceledException ignored) {
}
}, indicator);
}
@@ -88,29 +86,26 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
final TLongArrayList times = new TLongArrayList();
final long end = warmupEnd + 1000;
ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
final Alarm alarm = new Alarm(Alarm.ThreadToUse.OWN_THREAD, getTestRootDisposable());
ProgressIndicatorEx indicator = (ProgressIndicatorEx)ProgressIndicatorProvider.getGlobalProgressIndicator();
prevTime = System.currentTimeMillis();
assert indicator != null;
indicator.addStateDelegate(new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
now = System.currentTimeMillis();
if (now > warmupEnd) {
int delta = (int)(now - prevTime);
times.add(delta);
}
prevTime = now;
ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(() -> {
final Alarm alarm = new Alarm(Alarm.ThreadToUse.OWN_THREAD, getTestRootDisposable());
ProgressIndicatorEx indicator = (ProgressIndicatorEx)ProgressIndicatorProvider.getGlobalProgressIndicator();
prevTime = System.currentTimeMillis();
assert indicator != null;
indicator.addStateDelegate(new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
now = System.currentTimeMillis();
if (now > warmupEnd) {
int delta = (int)(now - prevTime);
times.add(delta);
}
});
while (System.currentTimeMillis() < end) {
ProgressManager.checkCanceled();
prevTime = now;
}
alarm.cancelAllRequests();
});
while (System.currentTimeMillis() < end) {
ProgressManager.checkCanceled();
}
alarm.cancelAllRequests();
}, "", false, getProject(), null, "");
long averageDelay = ArrayUtil.averageAmongMedians(times.toNativeArray(), 5);
System.out.println("averageDelay = " + averageDelay);
@@ -137,11 +132,8 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
while (!insideReadAction.get()) {
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
assertTrue(indicator.isCanceled());
}
ApplicationManager.getApplication().runWriteAction(() -> {
assertTrue(indicator.isCanceled());
});
assertTrue(indicator.isCanceled());
}
@@ -149,44 +141,24 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
public void testThereIsNoDelayBetweenIndicatorCancelAndProgressManagerCheckCanceled() throws Throwable {
for (int i=0; i<100;i++) {
final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
List<Thread> threads = ContainerUtil.map(Collections.nCopies(10, ""), new Function<String, Thread>() {
@Override
public Thread fun(String s) {
return new Thread(new Runnable() {
@Override
public void run() {
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(new Random().nextInt(100));
indicator.cancel();
ProgressManager.checkCanceled();
fail("checkCanceled() must know about canceled indicator even from different thread");
}
catch (ProcessCanceledException ignored) {
}
catch (Throwable e) {
exception = e;
}
}
}, indicator);
}
},"indicator test"){{start();}};
}
});
ContainerUtil.process(threads, new Processor<Thread>() {
@Override
public boolean process(Thread thread) {
try {
thread.join();
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
return true;
}
});
List<Thread> threads = ContainerUtil.map(Collections.nCopies(10, ""),
s -> new Thread(() -> ProgressManager.getInstance().executeProcessUnderProgress(() -> {
try {
Thread.sleep(new Random().nextInt(100));
indicator.cancel();
ProgressManager.checkCanceled();
fail("checkCanceled() must know about canceled indicator even from different thread");
}
catch (ProcessCanceledException ignored) {
}
catch (Throwable e) {
exception = e;
}
}, indicator), "indicator test"));
threads.forEach(Thread::start);
for (Thread thread : threads) {
thread.join();
}
}
if (exception != null) throw exception;
}
@@ -203,7 +175,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
taskCanceled = taskSucceeded = false;
exception = null;
Future<?> future = ((ProgressManagerImpl)ProgressManager.getInstance()).runProcessWithProgressAsynchronously(
new Task.Backgroundable(getProject(), "xxx") {
new Task.Backgroundable(getProject(), "Xxx") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
@@ -218,11 +190,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
checkCanceledCalled = true;
throw e;
}
catch (RuntimeException e) {
exception = e;
throw e;
}
catch (Error e) {
catch (RuntimeException | Error e) {
exception = e;
throw e;
}
@@ -274,20 +242,12 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
private void ensureCheckCanceledCalled(@NotNull ProgressIndicator indicator) {
myFlag = false;
Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myTestRootDisposable);
alarm.addRequest(new Runnable() {
@Override
public void run() {
myFlag = true;
}
}, 100);
alarm.addRequest(() -> myFlag = true, 100);
final long start = System.currentTimeMillis();
try {
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
while (System.currentTimeMillis() - start < 10000) {
ProgressManager.checkCanceled();
}
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
while (System.currentTimeMillis() - start < 10000) {
ProgressManager.checkCanceled();
}
}, indicator);
fail("must have thrown PCE");
@@ -315,38 +275,32 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
public void testNestedIndicatorsAreCanceledRight() {
checkCanceledCalled = false;
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertTrue(indicator != null && !indicator.isCanceled());
indicator.cancel();
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(indicator.isCanceled());
final ProgressIndicatorEx nested = new ProgressIndicatorBase();
nested.addStateDelegate(new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
checkCanceledCalled = true;
}
});
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertTrue(indicator != null && !indicator.isCanceled());
indicator.cancel();
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(indicator.isCanceled());
final ProgressIndicatorEx nested = new ProgressIndicatorBase();
nested.addStateDelegate(new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
checkCanceledCalled = true;
}
});
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
ProgressIndicator indicator2 = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertTrue(indicator2 != null && !indicator2.isCanceled());
assertSame(indicator2, nested);
ProgressManager.checkCanceled();
}
}, nested);
ProgressIndicator indicator2 = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertTrue(indicator2 != null && !indicator2.isCanceled());
assertSame(indicator2, nested);
ProgressManager.checkCanceled();
}, nested);
ProgressIndicator indicator3 = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertSame(indicator, indicator3);
ProgressIndicator indicator3 = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertSame(indicator, indicator3);
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
}
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
}, new EmptyProgressIndicator());
assertFalse(checkCanceledCalled);
}
@@ -355,24 +309,18 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
EmptyProgressIndicator indicator1 = new EmptyProgressIndicator();
DelegatingProgressIndicator indicator2 = new DelegatingProgressIndicator(indicator1);
final DelegatingProgressIndicator indicator3 = new DelegatingProgressIndicator(indicator2);
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
ProgressIndicator current = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertSame(indicator3, current);
}
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
ProgressIndicator current = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertSame(indicator3, current);
}, indicator3);
assertFalse(checkCanceledCalled);
}
public void testProgressPerformance() {
PlatformTestUtil.startPerformanceTest("progress", 100, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
EmptyProgressIndicator indicator = new EmptyProgressIndicator();
for (int i=0;i<100000;i++) {
ProgressManager.getInstance().executeProcessUnderProgress(EmptyRunnable.getInstance(), indicator);
}
PlatformTestUtil.startPerformanceTest("progress", 100, () -> {
EmptyProgressIndicator indicator = new EmptyProgressIndicator();
for (int i=0;i<100000;i++) {
ProgressManager.getInstance().executeProcessUnderProgress(EmptyRunnable.getInstance(), indicator);
}
}).assertTiming();
}
@@ -385,17 +333,14 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
}
};
try {
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(!progress.isCanceled());
progress.cancel();
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(progress.isCanceled());
while (true) { // wait for PCE
ProgressManager.checkCanceled();
}
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(!progress.isCanceled());
progress.cancel();
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(progress.isCanceled());
while (true) { // wait for PCE
ProgressManager.checkCanceled();
}
}, ProgressWrapper.wrap(progress));
fail("PCE must have been thrown");
@@ -407,22 +352,19 @@ public class ProgressIndicatorTest extends LightPlatformTestCase {
public void testBombedIndicator() {
final int count = 10;
new BombedProgressIndicator(count).runBombed(new Runnable() {
@Override
public void run() {
for (int i = 0; i < count * 2; i++) {
TimeoutUtil.sleep(10);
try {
new BombedProgressIndicator(count).runBombed(() -> {
for (int i = 0; i < count * 2; i++) {
TimeoutUtil.sleep(10);
try {
ProgressManager.checkCanceled();
if (i >= count) {
ProgressManager.checkCanceled();
if (i >= count) {
ProgressManager.checkCanceled();
fail("PCE expected on " + i + "th check");
}
fail("PCE expected on " + i + "th check");
}
catch (ProcessCanceledException e) {
if (i < count) {
fail("Too early PCE");
}
}
catch (ProcessCanceledException e) {
if (i < count) {
fail("Too early PCE");
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,8 +43,8 @@ public class MessageBusTest extends TestCase {
void t22();
}
private static final Topic<T1Listener> TOPIC1 = new Topic<T1Listener>("T1", T1Listener.class);
private static final Topic<T2Listener> TOPIC2 = new Topic<T2Listener>("T2", T2Listener.class);
private static final Topic<T1Listener> TOPIC1 = new Topic<>("T1", T1Listener.class);
private static final Topic<T2Listener> TOPIC2 = new Topic<>("T2", T2Listener.class);
private class T1Handler implements T1Listener {
private final String id;
@@ -86,7 +86,7 @@ public class MessageBusTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
myBus = MessageBusFactory.newMessageBus(this);
myLog = new ArrayList<String>();
myLog = new ArrayList<>();
}
public void testNoListenersSubscribed() {
@@ -217,13 +217,10 @@ public class MessageBusTest extends TestCase {
new MessageBusImpl(this, childBus);
}
PlatformTestUtil.assertTiming("Too long", 3000, new Runnable() {
@Override
public void run() {
T1Listener publisher = myBus.syncPublisher(TOPIC1);
for (int i = 0; i < 1000000; i++) {
publisher.t11();
}
PlatformTestUtil.assertTiming("Too long", 3000, () -> {
T1Listener publisher = myBus.syncPublisher(TOPIC1);
for (int i = 0; i < 1000000; i++) {
publisher.t11();
}
});
}
@@ -231,15 +228,16 @@ public class MessageBusTest extends TestCase {
public void testStress() throws Throwable {
final int threadsNumber = 10;
final int iterationsNumber = 100;
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
final AtomicReference<Throwable> exception = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(threadsNumber);
final MessageBus parentBus = MessageBusFactory.newMessageBus("parent");
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < threadsNumber; i++) {
new Thread(String.valueOf(i)) {
Thread thread = new Thread(String.valueOf(i)) {
@Override
public void run() {
int remains = iterationsNumber;
try {
int remains = iterationsNumber;
while (remains-- > 0) {
//noinspection ThrowableResultOfMethodCallIgnored
if (exception.get() != null) {
@@ -255,13 +253,18 @@ public class MessageBusTest extends TestCase {
latch.countDown();
}
}
}.start();
};
thread.start();
threads.add(thread);
}
latch.await();
final Throwable e = exception.get();
if (e != null) {
throw e;
}
for (Thread thread : threads) {
thread.join();
}
}
@@ -1,3 +1,18 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.net.ssl;
import com.intellij.openapi.application.ApplicationManager;
@@ -112,6 +127,7 @@ public class CertificateTest extends LightPlatformTestCase {
final long interruptionTimeout = CertificateManager.DIALOG_VISIBILITY_TIMEOUT + 1000;
// Will be interrupted after at most interruptionTimeout (6 seconds originally)
Thread[] t = {null};
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
@@ -147,11 +163,13 @@ public class CertificateTest extends LightPlatformTestCase {
fail("Deadlock was not detected in time");
}
}
t[0] = thread;
}
}, ModalityState.any());
if (!throwableRef.isNull()) {
throw new AssertionError(throwableRef.get());
}
t[0].join();
}
@Override
@@ -17,10 +17,10 @@ package com.intellij.execution.testframework.sm;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.testframework.sm.runner.OutputLineSplitter;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.util.concurrency.FutureResult;
import com.intellij.testFramework.PlatformTestCase;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
@@ -28,7 +28,7 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class OutputLineSplitterTest extends UsefulTestCase {
public class OutputLineSplitterTest extends PlatformTestCase {
private static final Key RED = Key.create(OutputLineSplitterTest.class + ".RED");
private static final Key GREEN = Key.create(OutputLineSplitterTest.class + ".GREEN");
private static final Key BLUE = Key.create(OutputLineSplitterTest.class + ".BLUE");
@@ -183,7 +183,7 @@ public class OutputLineSplitterTest extends UsefulTestCase {
isFinished.set(true);
for (Future<?> each : futures) {
each.get(10, TimeUnit.SECONDS);
each.get();
}
}
catch (Exception e) {
@@ -193,19 +193,6 @@ public class OutputLineSplitterTest extends UsefulTestCase {
}
private Future<?> execute(final Runnable runnable) {
final FutureResult<?> result = new FutureResult<Object>();
new Thread(new Runnable() {
@Override
public void run() {
try {
runnable.run();
result.set(null);
}
catch (Throwable e) {
result.setException(e);
}
}
},"line split").start();
return result;
return ApplicationManager.getApplication().executeOnPooledThread(runnable);
}
}
@@ -86,6 +86,8 @@ public abstract class MavenIndicesStressTest extends MavenIndicesTestCase implem
t2.join(100);
indices.close();
t1.join();
t2.join();
}
public void test2() throws Exception {
@@ -130,6 +132,8 @@ public abstract class MavenIndicesStressTest extends MavenIndicesTestCase implem
indices1.close();
indices2.close();
t1.join();
t2.join();
}
private static Thread createThread(final MavenIndex index, final AtomicInteger finishedCount) {
@@ -124,12 +124,9 @@ public class SvnBusyOnAddTest extends TestCase {
final Semaphore semaphoreWokeUp = new Semaphore();
final AtomicReference<Boolean> wasUp = new AtomicReference<Boolean>(false);
final ISVNStatusHandler handler = new ISVNStatusHandler() {
@Override
public void handleStatus(SVNStatus status) throws SVNException {
semaphore.waitFor();
wasUp.set(true);
}
final ISVNStatusHandler handler = status -> {
semaphore.waitFor();
wasUp.set(true);
};
semaphore.down();
@@ -137,19 +134,17 @@ public class SvnBusyOnAddTest extends TestCase {
semaphoreWokeUp.down();
final SVNException[] exception = new SVNException[1];
new Thread(new Runnable() {
@Override
public void run() {
try {
semaphoreMain.up();
readClient.doStatus(myWorkingCopyRoot, true, false, true, false, handler);
semaphoreWokeUp.up();
}
catch (SVNException e) {
exception[0] = e;
}
Thread thread = new Thread(() -> {
try {
semaphoreMain.up();
readClient.doStatus(myWorkingCopyRoot, true, false, true, false, handler);
semaphoreWokeUp.up();
}
},"svn test").start();
catch (SVNException e) {
exception[0] = e;
}
}, "svn test");
thread.start();
semaphoreMain.waitFor();
TimeoutUtil.sleep(5);
@@ -162,7 +157,9 @@ public class SvnBusyOnAddTest extends TestCase {
if (exception[0] != null) {
throw exception[0];
}
} finally {
thread.join();
}
finally {
ioFile.delete();
}
}
@@ -32,6 +32,8 @@ import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.io.ISVNSession;
import org.tmatesoft.svn.core.io.SVNRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
@@ -127,6 +129,7 @@ public class SvnCachingRepositoryPoolTest extends FileBasedTest {
}
}
Assert.assertTrue(!thread.isAlive());
thread.join();
Assert.assertNotNull(exc[0]);
//repository1.fireConnectionClosed(); // also test that used are also closed.. in dispose
@@ -151,7 +154,7 @@ public class SvnCachingRepositoryPoolTest extends FileBasedTest {
Assert.assertEquals(0, group.getInactiveSize());
}
private void testBigFlow(final SvnIdeaRepositoryPoolManager poolManager, boolean disposeAfter) throws SVNException {
private void testBigFlow(final SvnIdeaRepositoryPoolManager poolManager, boolean disposeAfter) throws SVNException, InterruptedException {
poolManager.setCreator(new ThrowableConvertor<SVNURL, SVNRepository, SVNException>() {
@Override
public SVNRepository convert(SVNURL svnurl) throws SVNException {
@@ -163,6 +166,7 @@ public class SvnCachingRepositoryPoolTest extends FileBasedTest {
final int[] cnt = new int[1];
cnt[0] = 25;
final SVNException[] exc = new SVNException[1];
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 25; i++) {
Runnable target = new Runnable() {
@Override
@@ -186,6 +190,7 @@ public class SvnCachingRepositoryPoolTest extends FileBasedTest {
};
Thread thread = new Thread(target, "svn cache");
thread.start();
threads.add(thread);
}
final long start = System.currentTimeMillis();
@@ -217,6 +222,10 @@ public class SvnCachingRepositoryPoolTest extends FileBasedTest {
Assert.assertEquals(0, group.getUsedSize());
Assert.assertEquals(0, group.getInactiveSize());
}
for (Thread thread : threads) {
thread.join();
}
}
private boolean timeout(long start) {
@@ -108,6 +108,8 @@ public class SvnLockingTest extends TestCase {
thread1.interrupt();
thread2.interrupt();
thread1.join();
thread2.join();
}
}
@@ -138,6 +140,8 @@ public class SvnLockingTest extends TestCase {
thread1.interrupt();
thread2.interrupt();
thread1.join();
thread2.join();
}
}
@@ -225,6 +229,9 @@ public class SvnLockingTest extends TestCase {
thread1.interrupt();
thread2.interrupt();
threadRead.interrupt();
thread1.join();
thread2.join();
threadRead.join();
}
}
@@ -57,5 +57,6 @@ public class VcsWaitForUpdateForTest extends Svn17TestCase {
}
assert Boolean.TRUE.equals(done.get());
thread.join();
}
}
@@ -57,5 +57,6 @@ public class VcsWaitForUpdateForTest extends Svn16TestCase {
}
assert Boolean.TRUE.equals(done.get());
thread.join();
}
}
@@ -324,9 +324,10 @@ public class PyConsoleTask extends PyExecutionFixtureTestTask {
myLen = s.length();
}
public void stop() {
public void stop() throws InterruptedException {
printToConsole();
myThread.interrupt();
myThread.join();
}
}
@@ -382,8 +382,9 @@ public abstract class PyBaseDebuggerTask extends PyExecutionFixtureTestTask {
}
}
public void stop() {
public void stop() throws InterruptedException {
myThread.interrupt();
myThread.join();
}
}
}
@@ -28,7 +28,6 @@ import com.intellij.semantic.SemService;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.Timings;
import com.intellij.util.Function;
import com.intellij.util.Processor;
import com.intellij.util.TimeoutUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xml.impl.DomFileElementImpl;
@@ -121,33 +120,23 @@ public class DomConcurrencyStressTest extends DomTestCase {
int N = 8;
final CountDownLatch reads = new CountDownLatch(N);
List<Thread> threads = ContainerUtil.map(Collections.nCopies(N, ""), new Function<String, Thread>() {
List<Thread> threads = ContainerUtil.map(Collections.nCopies(N, ""), (Function<String, Thread>)s -> new Thread("dom concurrency") {
@Override
public Thread fun(String s) {
return new Thread("dom concurrency") {
@Override
public void run() {
try {
runnable.run();
}
catch (Throwable e) {
exc.set(e);
}
finally {
reads.countDown();
}
}
};
}
});
ContainerUtil.process(threads, new Processor<Thread>() {
@Override
public boolean process(Thread thread) {
thread.start();
return true;
public void run() {
try {
runnable.run();
}
catch (Throwable e) {
exc.set(e);
}
finally {
reads.countDown();
}
}
});
threads.forEach(Thread::start);
reads.await();
if (!exc.isNull()) {
throw exc.get();
@@ -207,26 +196,19 @@ public class DomConcurrencyStressTest extends DomTestCase {
assert bigXml != null;
final XmlFile file = (XmlFile)PsiManager.getInstance(ourProject).findFile(bigXml);
runThreads(42, new Runnable() {
runThreads(42, () -> {
final Random random = new Random();
for (int i = 0; i < ITERATIONS; i++) {
ApplicationManager.getApplication().runReadAction(() -> {
int offset = random.nextInt(file.getTextLength() - 10);
XmlTag tag = PsiTreeUtil.findElementOfClassAtOffset(file, offset, XmlTag.class, false);
assert tag != null : offset;
DomElement element = DomUtil.getDomElement(tag);
assert element instanceof MyAllCustomElement : element;
});
@Override
public void run() {
final Random random = new Random();
for (int i = 0; i < ITERATIONS; i++) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
int offset = random.nextInt(file.getTextLength() - 10);
XmlTag tag = PsiTreeUtil.findElementOfClassAtOffset(file, offset, XmlTag.class, false);
assert tag != null : offset;
DomElement element = DomUtil.getDomElement(tag);
assert element instanceof MyAllCustomElement : element;
}
});
if (random.nextInt(50) == 0) {
SemService.getSemService(getProject()).clearCache();
}
if (random.nextInt(50) == 0) {
SemService.getSemService(getProject()).clearCache();
}
}
});