mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make test load-independent
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.util;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ public abstract class WaitFor {
|
||||
private long myWaitTime;
|
||||
private boolean myInterrupted;
|
||||
private volatile boolean myConditionRealized;
|
||||
@NonNls public static final String WAIT_FOR_THREAD_NAME = "WaitFor thread";
|
||||
@NonNls private static final String WAIT_FOR_THREAD_NAME = "WaitFor thread";
|
||||
private Thread myThread;
|
||||
|
||||
/** Blocking call */
|
||||
public WaitFor() {
|
||||
@@ -57,7 +59,7 @@ public abstract class WaitFor {
|
||||
|
||||
/** Non-blocking call */
|
||||
public WaitFor(final int timeoutMsecs, final Runnable toRunOnTrue) {
|
||||
new Thread(WAIT_FOR_THREAD_NAME) {
|
||||
myThread = new Thread(WAIT_FOR_THREAD_NAME) {
|
||||
@Override
|
||||
public void run() {
|
||||
myConditionRealized = new WaitFor(timeoutMsecs) {
|
||||
@@ -69,8 +71,10 @@ public abstract class WaitFor {
|
||||
|
||||
if (myConditionRealized) {
|
||||
toRunOnTrue.run();
|
||||
} }
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
};
|
||||
myThread.start();
|
||||
}
|
||||
|
||||
public long getWaitedTime() {
|
||||
@@ -93,4 +97,12 @@ public abstract class WaitFor {
|
||||
public void assertCompleted(String message) {
|
||||
assert condition(): message;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void join() throws InterruptedException {
|
||||
Thread thread = myThread;
|
||||
if (thread != null) {
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user