Skip to content

Commit d430706

Browse files
matMainRo
authored andcommitted
Add tests for absolute first emit
1 parent d06be56 commit d430706

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

tests/test_observable/test_timer.py

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,60 @@ def create():
128128
results = scheduler.start(create)
129129
assert results.messages == [on_next(500, 0), on_next(800, 1)]
130130

131+
def test_periodic_timer_repeat(self):
132+
scheduler = TestScheduler()
133+
t = reactivex.timer(duetime=130, period=200, scheduler=scheduler)
134+
135+
def create():
136+
return t.pipe(operators.take(3), operators.repeat())
137+
138+
results = scheduler.start(create)
139+
assert results.messages == [
140+
on_next(330, 0),
141+
on_next(530, 1),
142+
on_next(730, 2),
143+
on_next(860, 0),
144+
]
145+
146+
def test_periodic_timer_repeat_with_absolute_datetime(self):
147+
scheduler = TestScheduler()
148+
t = reactivex.timer(
149+
duetime=scheduler.to_datetime(360), period=200, scheduler=scheduler
150+
) # here we have an absolute first value, so on second subscription, the timer should emit immediately
151+
152+
def create():
153+
return t.pipe(operators.take(3), operators.repeat())
154+
155+
results = scheduler.start(create)
156+
assert results.messages == [
157+
on_next(360, 0),
158+
on_next(560, 1),
159+
on_next(760, 2),
160+
on_next(
161+
760, 0
162+
), # our duetime is absolute and in the past so new sub emits immediately
163+
on_next(960, 1),
164+
]
165+
166+
def test_periodic_timer_repeat_with_relative_timespan(self):
167+
scheduler = TestScheduler()
168+
t = reactivex.timer(
169+
duetime=scheduler.to_timedelta(130),
170+
period=scheduler.to_timedelta(250),
171+
scheduler=scheduler,
172+
)
173+
174+
def create():
175+
return t.pipe(operators.take(3), operators.repeat())
176+
177+
results = scheduler.start(create)
178+
assert results.messages == [
179+
on_next(330, 0),
180+
on_next(580, 1),
181+
on_next(830, 2),
182+
on_next(960, 0),
183+
]
184+
131185
def test_periodic_timer_second_subscription(self):
132186
scheduler = TestScheduler()
133187
t = reactivex.timer(duetime=200, period=300, scheduler=scheduler)
@@ -149,7 +203,7 @@ def create():
149203
on_next(800, (1, "second")),
150204
]
151205

152-
def test_on_off_timer_repeat(self):
206+
def test_one_off_timer_repeat(self):
153207
scheduler = TestScheduler()
154208
t = reactivex.timer(duetime=230, scheduler=scheduler)
155209

@@ -162,18 +216,3 @@ def create():
162216
on_next(660, 0),
163217
on_next(890, 0),
164218
]
165-
166-
def test_periodic_timer_repeat(self):
167-
scheduler = TestScheduler()
168-
t = reactivex.timer(duetime=130, period=200, scheduler=scheduler)
169-
170-
def create():
171-
return t.pipe(operators.take(3), operators.repeat())
172-
173-
results = scheduler.start(create)
174-
assert results.messages == [
175-
on_next(330, 0),
176-
on_next(530, 1),
177-
on_next(730, 2),
178-
on_next(860, 0),
179-
]

0 commit comments

Comments
 (0)