Skip to content

Commit 08be741

Browse files
Piotr Wittchenakarnokd
Piotr Wittchen
authored andcommitted
Refactoring SingleSchedulerTest. Now it extends AbstractSchedulerTests, so redundant tests could be removed in favor of abstract tests. (#5462)
1 parent 1327982 commit 08be741

File tree

1 file changed

+4
-59
lines changed

1 file changed

+4
-59
lines changed

src/test/java/io/reactivex/internal/schedulers/SingleSchedulerTest.java

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616
import static org.junit.Assert.*;
1717

18+
import io.reactivex.schedulers.AbstractSchedulerTests;
1819
import java.util.concurrent.*;
1920

2021
import org.junit.Test;
2122

2223
import io.reactivex.*;
2324
import io.reactivex.Scheduler.Worker;
2425
import io.reactivex.disposables.*;
25-
import io.reactivex.internal.disposables.SequentialDisposable;
2626
import io.reactivex.internal.functions.Functions;
2727
import io.reactivex.internal.schedulers.SingleScheduler.ScheduledWorker;
2828
import io.reactivex.schedulers.Schedulers;
2929

30-
public class SingleSchedulerTest {
30+
public class SingleSchedulerTest extends AbstractSchedulerTests {
3131

3232
@Test
3333
public void shutdownRejects() {
@@ -119,63 +119,8 @@ public void runnableDisposedAsyncTimed() throws Exception {
119119
}
120120
}
121121

122-
@Test(timeout = 10000)
123-
public void schedulePeriodicallyDirectZeroPeriod() throws Exception {
124-
Scheduler s = Schedulers.single();
125-
126-
for (int initial = 0; initial < 2; initial++) {
127-
final CountDownLatch cdl = new CountDownLatch(1);
128-
129-
final SequentialDisposable sd = new SequentialDisposable();
130-
131-
try {
132-
sd.replace(s.schedulePeriodicallyDirect(new Runnable() {
133-
int count;
134-
@Override
135-
public void run() {
136-
if (++count == 10) {
137-
sd.dispose();
138-
cdl.countDown();
139-
}
140-
}
141-
}, initial, 0, TimeUnit.MILLISECONDS));
142-
143-
assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
144-
} finally {
145-
sd.dispose();
146-
}
147-
}
122+
@Override protected Scheduler getScheduler() {
123+
return Schedulers.single();
148124
}
149125

150-
@Test(timeout = 10000)
151-
public void schedulePeriodicallyZeroPeriod() throws Exception {
152-
Scheduler s = Schedulers.single();
153-
154-
for (int initial = 0; initial < 2; initial++) {
155-
156-
final CountDownLatch cdl = new CountDownLatch(1);
157-
158-
final SequentialDisposable sd = new SequentialDisposable();
159-
160-
Scheduler.Worker w = s.createWorker();
161-
162-
try {
163-
sd.replace(w.schedulePeriodically(new Runnable() {
164-
int count;
165-
@Override
166-
public void run() {
167-
if (++count == 10) {
168-
sd.dispose();
169-
cdl.countDown();
170-
}
171-
}
172-
}, initial, 0, TimeUnit.MILLISECONDS));
173-
174-
assertTrue("" + initial, cdl.await(5, TimeUnit.SECONDS));
175-
} finally {
176-
sd.dispose();
177-
w.dispose();
178-
}
179-
}
180-
}
181126
}

0 commit comments

Comments
 (0)