Skip to content

Commit

Permalink
Tests: Improve the timing of bootstrapping the machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Nov 28, 2021
1 parent 0414e02 commit 7a4dc1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
13 changes: 9 additions & 4 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import pytest
import logging

import pytest_twisted

from kotori import KotoriBootloader
from test.util import boot_kotori
from test.util import boot_kotori, sleep
from test.settings.mqttkit import influx_sensors, influx_events, grafana

logger = logging.getLogger(__name__)

STARTUP_DELAY = 1.5

# Disable ellipsis truncation
# https://stackoverflow.com/questions/19171554/preventing-truncation-of-long-strings-in-pytest/60321834#60321834
Expand All @@ -23,7 +26,7 @@

def create_machinery(config, scope="package"):

#@pytest_twisted.inlineCallbacks
@pytest_twisted.inlineCallbacks
@pytest.fixture(scope=scope)
def machinery():

Expand All @@ -34,9 +37,11 @@ def machinery():
result = boot_kotori(config)
assert isinstance(result, KotoriBootloader)

#pytest_twisted.blockon(result)
logger.info(f"Delaying for {STARTUP_DELAY} seconds to wait for the machinery to start")
waiter = sleep(STARTUP_DELAY)
pytest_twisted.blockon(waiter)

logger.info('Machinery is almost ready')
logger.info('Machinery is ready')
yield result

return machinery
Expand Down
5 changes: 0 additions & 5 deletions test/test_airrohr.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ def test_airrohr_http_json(machinery_basic, create_influxdb, reset_influxdb):
and proof it is stored in the InfluxDB database.
"""

# Wait for some time to let the machinery spin up.
yield sleep(PROCESS_DELAY_MQTT)
yield sleep(PROCESS_DELAY_MQTT)
yield sleep(PROCESS_DELAY_MQTT)

# Submit a single measurement, without timestamp.
yield threads.deferToThread(http_json_sensor, settings.channel_path_airrohr, data_in)

Expand Down
5 changes: 0 additions & 5 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ def test_mqtt_strategy_lan(machinery_basic, create_influxdb, reset_influxdb, res
that a corresponding datasource and a dashboard was created in Grafana.
"""

# Wait for some time to spin up the machinery.
yield sleep(PROCESS_DELAY_MQTT)
yield sleep(PROCESS_DELAY_MQTT)
yield sleep(PROCESS_DELAY_MQTT)

# Submit a single measurement, without timestamp.
data = {
'temperature': 42.84,
Expand Down

0 comments on commit 7a4dc1a

Please sign in to comment.