Fix unit tests that sometimes failed due timeouts (#10698)
Motivation: We had two unit tests that sometimes failed due timeouts. After insepecting these I noticed these can be improved to run faster while still do the right validation Modifications: - Only submit one task for execution per execute - Cleanup Result: No test failures due timeout
This commit is contained in:
parent
fbb42a292f
commit
cc79f5f4ff
@ -134,34 +134,22 @@ public class GlobalEventExecutorTest {
|
|||||||
//for https://github.com/netty/netty/issues/1614
|
//for https://github.com/netty/netty/issues/1614
|
||||||
//add scheduled task
|
//add scheduled task
|
||||||
TestRunnable t = new TestRunnable(0);
|
TestRunnable t = new TestRunnable(0);
|
||||||
ScheduledFuture<?> f = e.schedule(t, 1500, TimeUnit.MILLISECONDS);
|
final ScheduledFuture<?> f = e.schedule(t, 1500, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
final Runnable doNothing = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
//NOOP
|
|
||||||
}
|
|
||||||
};
|
|
||||||
final AtomicBoolean stop = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
//ensure always has at least one task in taskQueue
|
//ensure always has at least one task in taskQueue
|
||||||
//check if scheduled tasks are triggered
|
//check if scheduled tasks are triggered
|
||||||
try {
|
e.execute(new Runnable() {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!stop.get()) {
|
if (!f.isDone()) {
|
||||||
e.execute(doNothing);
|
e.execute(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
|
|
||||||
f.sync();
|
f.sync();
|
||||||
|
|
||||||
assertThat(t.ran.get(), is(true));
|
assertThat(t.ran.get(), is(true));
|
||||||
} finally {
|
|
||||||
stop.set(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestRunnable implements Runnable {
|
private static final class TestRunnable implements Runnable {
|
||||||
|
@ -374,34 +374,22 @@ public class SingleThreadEventExecutorTest {
|
|||||||
|
|
||||||
//add scheduled task
|
//add scheduled task
|
||||||
TestRunnable t = new TestRunnable();
|
TestRunnable t = new TestRunnable();
|
||||||
ScheduledFuture<?> f = executor.schedule(t, 1500, TimeUnit.MILLISECONDS);
|
final ScheduledFuture<?> f = executor.schedule(t, 1500, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
final Runnable doNothing = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
//NOOP
|
|
||||||
}
|
|
||||||
};
|
|
||||||
final AtomicBoolean stop = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
//ensure always has at least one task in taskQueue
|
//ensure always has at least one task in taskQueue
|
||||||
//check if scheduled tasks are triggered
|
//check if scheduled tasks are triggered
|
||||||
try {
|
executor.execute(new Runnable() {
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!stop.get()) {
|
if (!f.isDone()) {
|
||||||
executor.execute(doNothing);
|
executor.execute(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
|
|
||||||
f.sync();
|
f.sync();
|
||||||
|
|
||||||
assertThat(t.ran.get(), is(true));
|
assertThat(t.ran.get(), is(true));
|
||||||
} finally {
|
|
||||||
stop.set(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestRunnable implements Runnable {
|
private static final class TestRunnable implements Runnable {
|
||||||
|
Loading…
Reference in New Issue
Block a user