async def test_running_writer(mocked_influx, app, client, mocker): writer = influx.get_writer(app) await writer.write_soon(measurement='measurement', fields=dict(field1=1, field2=2), tags=dict(tag1=1, tag2=2)) await asyncio.sleep(0.01) assert writer.is_running assert not writer._pending assert mocked_influx.return_value.write.call_count == 1
async def test_run_error(mocked_influx, app, client, mocker): writer = influx.get_writer(app) mocked_influx.return_value.ping.side_effect = RuntimeError warn_mock = mocker.spy(influx.LOGGER, 'warn') await asyncio.sleep(0.01) assert not writer.is_running assert warn_mock.call_count == 1 await writer.close() assert warn_mock.call_count == 2
async def test_reconnect_fail(mocked_influx, app, client): db_client = mocked_influx.return_value db_client.ping.side_effect = ClientConnectionError writer = influx.InfluxWriter() await writer.start(app) await asyncio.sleep(0.01) assert influx.get_writer(app).is_running assert writer.is_running # Only the background writer managed to connect before we introduced errors assert db_client.create_database.call_count == 1
async def test_reconnect(mocked_influx, app, client): db_client = mocked_influx.return_value db_client.write.side_effect = [ClientConnectionError, RuntimeError] writer = influx.InfluxWriter() await writer.start(app) await writer.write_soon(measurement='measurement', fields=dict(field1=1, field2=2), tags=dict(tag1=1, tag2=2)) await asyncio.sleep(0.01) # the default writer connected just fine, and is idling # writing in first connection caused connection error # writing in second connection caused runtime error -> exit runner assert influx.get_writer(app).is_running assert not writer.is_running assert db_client.create_database.call_count == 3
async def test_setup(app, client): assert influx.get_writer(app) assert influx.get_relay(app) assert influx.get_client(app)