def test_advertiser_intermediate_failure(): @gen.coroutine def handle(request, response): body = yield request.get_body() if hb.count == 2: # fail the second request only raise Exception('great sadness') response.write_body(body) hb = Fakebahn(handle) try: hb.start() adv = hyperbahn.Advertiser( 'foo', TChannel('foo', known_peers=[hb.hostport]), interval_secs=0.2, interval_max_jitter_secs=0.0, ) yield adv.start() assert 1 == hb.count yield gen.sleep(0.25) assert 2 == hb.count yield gen.sleep(0.25) assert 3 == hb.count finally: hb.stop()
def test_advertiser_fail(): @gen.coroutine def fail(request, response): body = yield request.get_body() if hb.count == 1: # fail only the first request response.status_code = 1 response.write_body(body) hb = Fakebahn(fail) try: hb.start() adv = hyperbahn.Advertiser( 'foo', TChannel('foo', known_peers=[hb.hostport]), interval_secs=0.2, interval_max_jitter_secs=0.0, ) yield adv.start() assert 1 == hb.count yield gen.sleep(0.25) assert 2 == hb.count finally: hb.stop()
def test_advertiser_start_twice(echobahn): adv = hyperbahn.Advertiser( 'foo', TChannel('foo', known_peers=[echobahn.hostport]), ) yield adv.start() with pytest.raises(Exception) as exc_info: yield adv.start() assert 'already running' in str(exc_info) assert 1 == echobahn.count
def test_advertiser_stop(echobahn): adv = hyperbahn.Advertiser( 'foo', TChannel('foo', known_peers=[echobahn.hostport]), interval_secs=0.2, interval_max_jitter_secs=0.0, ) yield adv.start() assert 1 == echobahn.count yield gen.sleep(0.25) assert 2 == echobahn.count adv.stop() yield gen.sleep(0.25) assert 2 == echobahn.count adv.stop() # no-op assert 2 == echobahn.count
def test_advertiser_fail_to_start(): @gen.coroutine def fail(request, response): raise Exception('great sadness') hb = Fakebahn(fail) try: hb.start() adv = hyperbahn.Advertiser( 'foo', TChannel('foo', known_peers=[hb.hostport]), ) with pytest.raises(UnexpectedError) as exc_info: yield adv.start() assert 'great sadness' in str(exc_info) assert 1 == hb.count finally: hb.stop()