Skip to content

Refactoring SingleSchedulerTest #5462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

import static org.junit.Assert.*;

import io.reactivex.schedulers.AbstractSchedulerTests;
import java.util.concurrent.*;

import org.junit.Test;

import io.reactivex.*;
import io.reactivex.Scheduler.Worker;
import io.reactivex.disposables.*;
import io.reactivex.internal.disposables.SequentialDisposable;
import io.reactivex.internal.functions.Functions;
import io.reactivex.internal.schedulers.SingleScheduler.ScheduledWorker;
import io.reactivex.schedulers.Schedulers;

public class SingleSchedulerTest {
public class SingleSchedulerTest extends AbstractSchedulerTests {

@Test
public void shutdownRejects() {
Expand Down Expand Up @@ -119,63 +119,8 @@ public void runnableDisposedAsyncTimed() throws Exception {
}
}

@Test(timeout = 10000)
public void schedulePeriodicallyDirectZeroPeriod() throws Exception {
Scheduler s = Schedulers.single();

for (int initial = 0; initial < 2; initial++) {
final CountDownLatch cdl = new CountDownLatch(1);

final SequentialDisposable sd = new SequentialDisposable();

try {
sd.replace(s.schedulePeriodicallyDirect(new Runnable() {
int count;
@Override
public void run() {
if (++count == 10) {
sd.dispose();
cdl.countDown();
}
}
}, initial, 0, TimeUnit.MILLISECONDS));

assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
} finally {
sd.dispose();
}
}
@Override protected Scheduler getScheduler() {
return Schedulers.single();
}

@Test(timeout = 10000)
public void schedulePeriodicallyZeroPeriod() throws Exception {
Scheduler s = Schedulers.single();

for (int initial = 0; initial < 2; initial++) {

final CountDownLatch cdl = new CountDownLatch(1);

final SequentialDisposable sd = new SequentialDisposable();

Scheduler.Worker w = s.createWorker();

try {
sd.replace(w.schedulePeriodically(new Runnable() {
int count;
@Override
public void run() {
if (++count == 10) {
sd.dispose();
cdl.countDown();
}
}
}, initial, 0, TimeUnit.MILLISECONDS));

assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
} finally {
sd.dispose();
w.dispose();
}
}
}
}