Exemplo n.º 1
0
    def test_retry_observable_retry_count_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(1).pipe(ops.retry(3))
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        self.assertRaises(RxException, scheduler1.start)

        scheduler2 = TestScheduler()
        ys = reactivex.throw("ex").pipe(ops.retry(100))
        d = ys.subscribe(on_error=lambda ex: _raise("ex"),
                         scheduler=scheduler2)

        def dispose(_, __):
            d.dispose()

        scheduler2.schedule_absolute(0, dispose)
        scheduler2.start()

        scheduler3 = TestScheduler()
        zs = reactivex.return_value(1).pipe(ops.retry(100))
        zs.subscribe(on_completed=lambda: _raise("ex"), scheduler=scheduler3)

        with pytest.raises(RxException):
            scheduler3.start()

        xss = reactivex.create(lambda o: _raise("ex")).pipe(ops.retry(100))
        with pytest.raises(Exception):
            xss.subscribe()
Exemplo n.º 2
0
 def test_retry_observable_error(self):
     ex = "ex"
     scheduler = TestScheduler()
     xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2),
                                           on_next(200, 3),
                                           on_error(250, ex))
     results = scheduler.start(lambda: xs.pipe(ops.retry()), disposed=1100)
     assert results.messages == [
         on_next(300, 1),
         on_next(350, 2),
         on_next(400, 3),
         on_next(550, 1),
         on_next(600, 2),
         on_next(650, 3),
         on_next(800, 1),
         on_next(850, 2),
         on_next(900, 3),
         on_next(1050, 1),
     ]
     assert xs.subscriptions == [
         subscribe(200, 450),
         subscribe(450, 700),
         subscribe(700, 950),
         subscribe(950, 1100),
     ]
Exemplo n.º 3
0
def main():
    xs = reactivex.from_marbles("1-2-3-4-5-6-7-9-|").pipe(ops.publish())
    xs.pipe(ops.map(failing), ops.retry()).subscribe(print)

    xs.connect()  # Must connect. Cannot use ref_count() with publish()

    time.sleep(5)
Exemplo n.º 4
0
    def test_retry_observable_infinite(self):
        scheduler = TestScheduler()
        xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2),
                                              on_next(200, 3))
        results = scheduler.start(lambda: xs.pipe(ops.retry()))

        assert results.messages == [
            on_next(300, 1), on_next(350, 2),
            on_next(400, 3)
        ]
        assert xs.subscriptions == [subscribe(200, 1000)]
Exemplo n.º 5
0
    def test_retry_observable_throws(self):
        scheduler1 = TestScheduler()
        xs = reactivex.return_value(1).pipe(ops.retry())
        xs.subscribe(lambda x: _raise("ex"), scheduler=scheduler1)

        with pytest.raises(RxException):
            scheduler1.start()

        scheduler2 = TestScheduler()
        ys = reactivex.throw("ex").pipe(ops.retry())
        d = ys.subscribe(on_error=lambda ex: _raise("ex"),
                         scheduler=scheduler2)

        scheduler2.schedule_absolute(210, lambda sc, st: d.dispose())
        scheduler2.start()

        scheduler3 = TestScheduler()
        zs = reactivex.return_value(1).pipe(ops.retry())
        zs.subscribe(on_completed=lambda: _raise("ex"), scheduler=scheduler3)

        with pytest.raises(RxException):
            scheduler3.start()
Exemplo n.º 6
0
    def test_retry_observable_retry_count_dispose_iii(self):
        scheduler = TestScheduler()
        xs = scheduler.create_cold_observable(on_next(100, 1), on_next(150, 2),
                                              on_next(200, 3),
                                              on_completed(250))
        results = scheduler.start(lambda: xs.pipe(ops.retry(3)))

        assert results.messages == [
            on_next(300, 1),
            on_next(350, 2),
            on_next(400, 3),
            on_completed(450),
        ]
        assert xs.subscriptions == [subscribe(200, 450)]
Exemplo n.º 7
0
 def test_retry_observable_retry_count_dispose(self):
     scheduler = TestScheduler()
     ex = "ex"
     xs = scheduler.create_cold_observable(on_next(5, 1), on_next(10, 2),
                                           on_next(15, 3), on_error(20, ex))
     results = scheduler.start(lambda: xs.pipe(ops.retry(3)), disposed=231)
     assert results.messages == [
         on_next(205, 1),
         on_next(210, 2),
         on_next(215, 3),
         on_next(225, 1),
         on_next(230, 2),
     ]
     assert xs.subscriptions == [subscribe(200, 220), subscribe(220, 231)]