question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

assertSubscribed() always passes no matter how many times a Flowable is subscribed to.

See original GitHub issue

Hi,

Perhaps I’ve misunderstood the purpose of this API method, but the javadoc for assertSubscribed() that it should only pass if the Flowable has been subscribed to. However it seems to pass for me even if I don’t subscribe, eg the following passes:

Flowable.fromArray(1, 2).test().assertSubscribed();

It also suggests that it will pass if you only subscribe once, so the following test case should also fail, but seems to pass:

final Flowable<Integer> flowable = Flowable.fromArray(1, 2);
        flowable.subscribe();
        flowable.subscribe();
        flowable.test().assertSubscribed();

I’ve tested this in both rxjava 2.1.1 and 2.0.1.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeWhartoncommented, Jul 7, 2017

Calling test() calls subscribe automatically and returns the TestSubscriber. This would only then return false in this case of a broken Flowable that never called the onSubscribe method of the Subscriber.

On Fri, Jul 7, 2017 at 1:23 PM Richard Warburton notifications@github.com wrote:

Hi,

Perhaps I’ve misunderstood the purpose of this API method, but the javadoc for assertSubscribed() that it should only pass if the Flowable has been subscribed to. However it seems to pass for me even if I don’t subscribe, eg the following passes:

Flowable.fromArray(1, 2).test().assertSubscribed();

It also suggests that it will pass if you only subscribe once, so the following test case should also fail, but seems to pass:

final Flowable<Integer> flowable = Flowable.fromArray(1, 2); flowable.subscribe(); flowable.subscribe(); flowable.test().assertSubscribed();

I’ve tested this in both rxjava 2.1.1 and 2.0.1.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ReactiveX/RxJava/issues/5474, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEQRwIw5Ex8Ai1VGgWI3RWlZlVlkTks5sLmmFgaJpZM4ORNwN .

0reactions
RichardWarburtoncommented, Jul 10, 2017

Hi gents,

Thanks for your replies. I was aware of the big picture stuff here but I hadn’t put the implications together in my own mind. Thanks for clarifying the situation. I think the javadoc change you suggested would help confusion around the “subscribe once” aspect as well. I’ll close this issue.

regards,

Richard

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eager subscription - RxJava FAQ - Tomasz Nurkiewicz
This means no matter how heavy or long-running logic you place inside ... Even worse, even though eager() returns a Flowable it will...
Read more >
RxJava2 : How to test an observable is subscribed with ...
test() creates a subscription to the observable giving the following erroneous tests. // fixme: test passes but TestObservable is always true ...
Read more >
Testing RxJava code made easy - Medium
We want to assert that an Observable is being subscribed to, emits one value, completes and has no errors. Observable.just(1) .test() .
Read more >
TestObserver (RxJava Javadoc 3.1.5) - ReactiveX
Returns true if this TestObserver received a subscription. boolean, isDisposed(). Returns true if this test consumer was cancelled/disposed.
Read more >
4. Applying Reactive Programming to Existing Applications
For the time being, notice how we can lazily call bestSeller() without ... As long as no one subscribes to Observable<Ticket> , RxJava...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found