Skip to content
Snippets Groups Projects
Commit c5e5e6a7 authored by Simon Crowle's avatar Simon Crowle
Browse files

Refactors simulation configuration (time period) as fixture in TestSimulation class

conftest now simply returns an initialised simulator object
parent 86e07753
No related branches found
No related tags found
No related merge requests found
......@@ -22,23 +22,6 @@ def streaming_sim_config():
data_loaded = yaml.load(stream)
return data_loaded
@pytest.fixture(scope="module")
def streaming_sim_params(streaming_sim_config):
"""
Uses attributes from the local streaming_sim_config and creates a dictionary of simulation parameters
"""
sim_params = {}
sim_params["INFLUX_DB_URL"] = "http://" + streaming_sim_config['hosts'][0]['ip_address'] + ":8086"
sim_params["INFLUX_DB_NAME"] = streaming_sim_config['hosts'][1]['database_name'] # Note: could this be specified in the clmc-service instead?
sim_params["AGENT1_URL"] = "http://" + streaming_sim_config['hosts'][1]['ip_address'] + ":8186"
sim_params["AGENT2_URL"] = "http://" + streaming_sim_config['hosts'][2]['ip_address'] + ":8186"
sim_params["SIMULATION_TIME_SEC"] = 60 * 60
return sim_params
@pytest.fixture(params=[{'database': 'CLMCMetrics'}], scope='module')
def influx_db(streaming_sim_config, request):
"""
......@@ -49,24 +32,21 @@ def influx_db(streaming_sim_config, request):
:return: the created Influx DB client
"""
return InfluxDBClient(host=streaming_sim_config['hosts'][0]['ip_address'], port=8086, database=request.param['database'], timeout=10)
return InfluxDBClient(host=streaming_sim_config['hosts'][0]['ip_address'], port='8086', database=request.param['database'], timeout=10)
@pytest.fixture(scope='module')
def run_simulation_fixture(streaming_sim_params):
"""
A fixture, which checks if the the DB has been created, if not it runs the simulator with a 10 seconds timeout after that
"""
@pytest.fixture(scope="module")
def simulator( streaming_sim_config ):
influx_url = "http://" + streaming_sim_config['hosts'][0]['ip_address'] + ":8086"
influx_db_name = streaming_sim_config['hosts'][1]['database_name']
agent1_url = "http://" + streaming_sim_config['hosts'][1]['ip_address'] + ":8186"
agent2_url = "http://" + streaming_sim_config['hosts'][2]['ip_address'] + ":8186"
simulator = Sim( influx_url, influx_db_name, agent1_url, agent2_url )
simulator = Sim( streaming_sim_params['INFLUX_DB_URL'], streaming_sim_params['INFLUX_DB_NAME'], streaming_sim_params['AGENT1_URL'], streaming_sim_params['AGENT2_URL'])
dbs = simulator.db_client.get_list_database()
dbs = [db.get("name") for db in dbs]
# This check needed to be disabled as the CLMCMetrics database is always created when
# the test starts, irrespective of whether this is the 1st time or not
# if INFLUX_DB_NAME not in dbs:
simulator.reset()
simulator.run(streaming_sim_params['SIMULATION_TIME_SEC'])
print("10 seconds timeout is given so that the data could properly be inserted into the database.")
import time
time.sleep(10)
return simulator
\ No newline at end of file
#!/usr/bin/python3
import pytest
import time
class TestSimulation(object):
"""
A testing class used to group all the tests related to the simulation data
"""
@pytest.fixture(scope='class')
def run_simulator( self, simulator ):
simulator.run( 3600 )
print( "Waiting for INFLUX to finish receiving simulation data..." )
time.sleep( 10 ) # wait for data to finish arriving at the INFLUX database
@pytest.mark.parametrize("query, expected_result", [
('SELECT count(*) FROM "CLMCMetrics"."autogen"."cpu_usage"',
......@@ -25,7 +32,8 @@ class TestSimulation(object):
('SELECT count(*) FROM "CLMCMetrics"."autogen"."mpegdash_service_config" WHERE ipendpoint=\'adaptive_streaming_I1_apache2\'',
{"time" : "1970-01-01T00:00:00Z", "count_avg_running" : 3604, "count_avg_starting" : 3604, "count_avg_stopped" : 3604, "count_avg_stopping" : 3604, "count_running" : 3604, "count_starting" : 3604, "count_stopped" : 3604, "count_stopping" : 3604}),
])
def test_simulation(self, query, expected_result, influx_db, run_simulation_fixture):
def test_simulation( self, run_simulator, influx_db, query, expected_result ):
"""
This is the entry point of the test. This method will be found and executed when the module is ran using pytest
......@@ -36,7 +44,6 @@ class TestSimulation(object):
"""
# pytest automatically goes through all queries under test, declared in the parameters decorator
print("\n") # prints a blank line for formatting purposes
# the raise_errors=False argument is given so that we could actually test that the DB didn't return any errors instead of raising an exception
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment