Skip to content

Commit

Permalink
Give unit test some room for scheduler variability
Browse files Browse the repository at this point in the history
- I specifically want to be testing with real threads here and not virtual time or a synchronous sequence so am giving it a range of counts that are acceptable
  • Loading branch information
benjchristensen committed Jun 5, 2013
1 parent eb932d8 commit 2120103
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rxjava-core/src/main/java/rx/operators/OperationGroupBy.java
Original file line number Diff line number Diff line change
@@ -464,7 +464,7 @@ public void testUnsubscribe() throws InterruptedException {
@Override
public Subscription call(final Observer<Event> observer) {
final BooleanSubscription s = new BooleanSubscription();
System.out.println("*** Subscribing to EventStream ***");
System.out.println("testUnsubscribe => *** Subscribing to EventStream ***");
subscribeCounter.incrementAndGet();
new Thread(new Runnable() {

@@ -501,7 +501,7 @@ public Integer call(Event e) {

@Override
public Observable<String> call(GroupedObservable<Integer, Event> eventGroupedObservable) {
System.out.println("GroupedObservable Key: " + eventGroupedObservable.getKey());
System.out.println("testUnsubscribe => GroupedObservable Key: " + eventGroupedObservable.getKey());
groupCounter.incrementAndGet();

return eventGroupedObservable
@@ -510,7 +510,7 @@ public Observable<String> call(GroupedObservable<Integer, Event> eventGroupedObs

@Override
public String call(Event event) {
return "Source: " + event.source + " Message: " + event.message;
return "testUnsubscribe => Source: " + event.source + " Message: " + event.message;
}
});

@@ -540,10 +540,10 @@ public void onNext(String outputMessage) {
assertEquals(1, groupCounter.get());
assertEquals(20, eventCounter.get());
// sentEvents will go until 'eventCounter' hits 20 and then unsubscribes
// which means it will also send (but ignore) the 19 events for the other group
// which means it will also send (but ignore) the 19/20 events for the other group
// It will not however send all 100 events.
assertEquals(39, sentEventCounter.get());

assertEquals(39, sentEventCounter.get(), 2);
// gave it a delta of 2 so the threading/unsubscription race has wiggle
}

private static class Event {

0 comments on commit 2120103

Please sign in to comment.