Skip to content

Commit

Permalink
Subscribeon: test that the right scheduler is passed to the subscribe…
Browse files Browse the repository at this point in the history
… function of the source.
  • Loading branch information
jcafhe committed Feb 20, 2025
1 parent 2ae9fa4 commit 66699e0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/test_observable/test_subscribeon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from reactivex import operators as ops
from reactivex import operators as ops, create as rx_create
from reactivex.testing import ReactiveTest, TestScheduler

on_next = ReactiveTest.on_next
Expand Down Expand Up @@ -71,6 +71,28 @@ def create():
assert results.messages == []
assert xs.subscriptions == [subscribe(200, 1000)]

def test_subscribe_on_scheduler_forwarding(self):
scheduler = TestScheduler()
forwarded_sheduler = None

def source():
def subscribe(observer, _scheduler):
nonlocal forwarded_sheduler
forwarded_sheduler = _scheduler

def action_on_completed(_, __):
observer.on_completed()

return _scheduler.schedule_absolute(250, action_on_completed)

return rx_create(subscribe)

def create():
return source().pipe(ops.subscribe_on(scheduler))

results = scheduler.start(create)
assert forwarded_sheduler is scheduler
assert results.messages == [on_completed(250)]

if __name__ == "__main__":
unittest.main()

0 comments on commit 66699e0

Please sign in to comment.