Skip to content

Commit

Permalink
Reusing the container between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson committed Feb 7, 2025
1 parent 857f44e commit 268a4ec
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions fedn/tests/stores/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection
11 changes: 7 additions & 4 deletions fedn/tests/stores/helpers/database_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def network_id():
return "test_network"

@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def mongo_connection():
_, port = start_mongodb_container()

Expand All @@ -30,7 +30,7 @@ def mongo_config():

stop_mongodb_container()

@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def sql_connection():


Expand All @@ -46,9 +46,12 @@ def sql_config():
patch('fedn.network.storage.dbconnection.get_network_config', return_value=network_id()):
return DatabaseConnection(force_create_new=True)

@pytest.fixture(scope="module")
@pytest.fixture(scope="pack")
def postgres_connection():
print("Starting postgres container")
_, port = start_postgres_container()



def postgres_config():
return {
Expand All @@ -65,5 +68,5 @@ def postgres_config():
with patch('fedn.network.storage.dbconnection.get_statestore_config', return_value=postgres_config()), \
patch('fedn.network.storage.dbconnection.get_network_config', return_value=network_id()):
yield DatabaseConnection(force_create_new=True)

print("Stopping postgres container")
stop_postgres_container()
4 changes: 4 additions & 0 deletions fedn/tests/stores/helpers/mongo_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ def stop_mongodb_container():
container = client.containers.get(CONTAINER_NAME)
container.stop()
container.remove(v=True, force=True)
try:
container.wait(condition="removed")
except docker.errors.NotFound:
pass


4 changes: 4 additions & 0 deletions fedn/tests/stores/helpers/postgres_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ def stop_postgres_container():
container = client.containers.get(CONTAINER_NAME)
container.stop()
container.remove(v=True, force=True)
try:
container.wait(condition="removed")
except docker.errors.NotFound:
pass


2 changes: 1 addition & 1 deletion fedn/tests/stores/test_client_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import uuid

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection


@pytest.fixture
def test_clients():
Expand Down
2 changes: 1 addition & 1 deletion fedn/tests/stores/test_combiner_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import uuid

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection



@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion fedn/tests/stores/test_model_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import uuid

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection

@pytest.fixture
def test_models():
Expand Down
1 change: 0 additions & 1 deletion fedn/tests/stores/test_package_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import uuid

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection

@pytest.fixture
def test_packages():
Expand Down
1 change: 0 additions & 1 deletion fedn/tests/stores/test_prediction_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import itertools

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection



Expand Down
1 change: 0 additions & 1 deletion fedn/tests/stores/test_round_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import itertools

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection



Expand Down
3 changes: 1 addition & 2 deletions fedn/tests/stores/test_session_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import itertools

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection


@pytest.fixture
def test_sessions():
start_time = datetime.datetime(2021, 1, 4, 1, 2, 4)

model = {"id":str(uuid.uuid4()), "key":"models", "model":"test_model1", "parent_model":"test_parent_model", "session_id":None, "committed_at":start_time, "name":"test_name1", "active":True}
model = {"id":str(uuid.uuid4()), "key":"models", "model":str(uuid.uuid4()), "parent_model":"test_parent_model", "session_id":None, "committed_at":start_time, "name":"test_name1", "active":True}

session_config = {"aggregator":"test_aggregator", "round_timeout":100, "buffer_size":100, "delete_models_storage":True,
"clients_required":10, "validate":True, "helper_type":"test_helper_type", "model_id":model["model"]}
Expand Down
2 changes: 0 additions & 2 deletions fedn/tests/stores/test_status_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import itertools

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection


@pytest.fixture
def test_statuses():
Expand Down
3 changes: 0 additions & 3 deletions fedn/tests/stores/test_validation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import itertools

from fedn.network.storage.dbconnection import DatabaseConnection
from fedn.tests.stores.helpers.database_helper import mongo_connection, sql_connection, postgres_connection



@pytest.fixture
def test_validations():
Expand Down

0 comments on commit 268a4ec

Please sign in to comment.