Skip to content

Commit

Permalink
fix test no backend (#106)
Browse files Browse the repository at this point in the history
* dummy change

* change test order

* Revert "change test order"

This reverts commit 9ed7a43.

* force serial tests

* Revert "force serial tests"

This reverts commit 887a888.

* explicitly stop mock_backend to be unavailable

* stop httpserver properly

* test mock server lifetime

* mv test

* right port

* test order

* killing processes

---------

Co-authored-by: burnout87 <[email protected]>
  • Loading branch information
dsavchenko and burnout87 authored Aug 15, 2024
1 parent 9ea4d3c commit 03fb407
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cdci_data_analysis.pytest_fixtures import (
kill_child_processes,
dispatcher_debug,
dispatcher_test_conf_fn,
dispatcher_test_conf_with_external_products_url_fn,
Expand Down Expand Up @@ -192,7 +193,18 @@ def startup_check(self):
logfile = xprocess.ensure("nb2service", Starter)

except Exception as e:
xprocess.getinfo("nb2service").terminate()
process_info = xprocess.getinfo('nb2service')
pid = process_info.pid
kill_child_processes(pid, signal.SIGINT)
os.kill(pid, signal.SIGINT)
process_info.terminate()
raise e
yield 'http://localhost:9393/'
xprocess.getinfo("nb2service").terminate()
process_info = xprocess.getinfo('nb2service')
pid = process_info.pid

kill_child_processes(pid, signal.SIGINT)
os.kill(pid, signal.SIGINT)

process_info.terminate()

38 changes: 20 additions & 18 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,26 @@ def test_discover_plugin():
import cdci_data_analysis.plugins.importer as importer

assert 'dispatcher_plugin_nb2workflow' in importer.cdci_plugins_dict.keys()



def test_instrument_backend_unavailable(dispatcher_live_fixture):
# current behaviour is to have instrument with no products, could be changed in the future
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)

c = requests.get(server + "/api/meta-data",
params = {'instrument': 'example0'})
logger.info("content: %s", c.text)
jdata = c.json()
logger.info(json.dumps(jdata, indent=4, sort_keys=True))
logger.info(jdata)
assert c.status_code == 200
for elem in jdata[0]:
if isinstance(elem, dict) and 'prod_dict' in elem.keys():
prod_dict = elem['prod_dict']
assert prod_dict == {}


def test_instrument_available(dispatcher_live_fixture, mock_backend):
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)
Expand Down Expand Up @@ -133,23 +152,6 @@ def test_instrument_products(dispatcher_live_fixture, mock_backend):
'lightcurve': 'lightcurve_query',
'table': 'table_query'}

def test_instrument_backend_unavailable(dispatcher_live_fixture):
# current behaviour is to have instrument with no products, could be changed in the future
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)

c = requests.get(server + "/api/meta-data",
params = {'instrument': 'example0'})
logger.info("content: %s", c.text)
jdata = c.json()
logger.info(json.dumps(jdata, indent=4, sort_keys=True))
logger.info(jdata)
assert c.status_code == 200
for elem in jdata[0]:
if isinstance(elem, dict) and 'prod_dict' in elem.keys():
prod_dict = elem['prod_dict']
assert prod_dict == {}

def test_instrument_added(conf_file, dispatcher_live_fixture, mock_backend):
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)
Expand Down

0 comments on commit 03fb407

Please sign in to comment.