def observe_process(observer: Observable, command: str): process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) while True: output = process.stdout.readline() if output == b'' and process.poll() is not None: break if output: observer.on_next(output.decode('cp866')) observer.on_completed()
async def test_heartbeat( test: BaseHealthWatchdogTests, health_obs: Observable, source: Observable, factory: Callable[[str], Any], ): """ :param health_obs: Observable[BasicHealthModel], the observable of the heartbeat events :param source: Observable[SourceType], the observable that should trigger heartbeat events :param factory: Callable[[str], SourceType], a factory function that returns an object of the source observable sequence type """ health = None def assign(v): nonlocal health health = v health_obs.subscribe(assign) source.on_next(factory("test_id")) test.scheduler.advance_by(0) test.assertEqual(health.health_status, ttm.HealthStatus.HEALTHY) test.assertEqual(health.id_, "test_id") # it should not be dead yet test.scheduler.advance_by(HealthWatchdog.LIVELINESS / 2) test.assertEqual(health.health_status, ttm.HealthStatus.HEALTHY) test.assertEqual(health.id_, "test_id") # # it should be dead now because the time between states has reached the threshold test.scheduler.advance_by(HealthWatchdog.LIVELINESS / 2) test.assertEqual(health.health_status, ttm.HealthStatus.DEAD) test.assertEqual(health.id_, "test_id") # # it should become alive again when a new state is emitted source.on_next(factory("test_id")) test.assertEqual(health.health_status, ttm.HealthStatus.HEALTHY) test.assertEqual(health.id_, "test_id")