Skip to content

Commit

Permalink
added new gateway connection tests for kubernetes
Browse files Browse the repository at this point in the history
fixed stack integration tests
  • Loading branch information
rasswanth-s committed Oct 15, 2023
1 parent c8da625 commit b6dc962
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 16 deletions.
16 changes: 16 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# third party
import _pytest
import pytest


def pytest_configure(config: _pytest.config.Config) -> None:
config.addinivalue_line("markers", "frontend: frontend integration tests")
config.addinivalue_line("markers", "network: network integration tests")


@pytest.fixture
def gateway_port() -> int:
return 9081


@pytest.fixture
def domain_1_port() -> int:
return 9082


@pytest.fixture
def domain_2_port() -> int:
return 9083
2 changes: 1 addition & 1 deletion tests/integration/network/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_client_type(node_metadata):


@pytest.mark.parametrize(
"node_metadata", [(NETWORK_PORT, "test_gateway_1"), (DOMAIN_PORT, "test_domain_1")]
"node_metadata", [(NETWORK_PORT, "test-gateway-1"), (DOMAIN_PORT, "test-domain-1")]
)
@pytest.mark.network
def test_client_name(node_metadata):
Expand Down
52 changes: 52 additions & 0 deletions tests/integration/network/gateway_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# syft absolute
import syft as sy
from syft.abstract_node import NodeType
from syft.client.domain_client import DomainClient
from syft.client.gateway_client import GatewayClient
from syft.service.network.node_peer import NodePeer
from syft.service.response import SyftSuccess
from syft.service.user.user_roles import ServiceRole


def test_domain_connect_to_gateway(domain_1_port, gateway_port):
gateway_client: GatewayClient = sy.login(
port=gateway_port, email="[email protected]", password="changethis"
)

domain_client: DomainClient = sy.login(
port=domain_1_port, email="[email protected]", password="changethis"
)

result = domain_client.connect_to_gateway(gateway_client)
assert isinstance(result, SyftSuccess)

assert len(domain_client.peers) == 1
assert len(gateway_client.peers) == 1

proxy_domain_client = gateway_client.peers[0]
domain_peer = domain_client.peers[0]

assert isinstance(proxy_domain_client, DomainClient)
assert isinstance(domain_peer, NodePeer)

# Domain's peer is a gateway and vice-versa
assert domain_peer.node_type == NodeType.GATEWAY

assert gateway_client.name == domain_peer.name
assert domain_client.name == proxy_domain_client.name

assert len(gateway_client.domains) == 1
assert len(gateway_client.enclaves) == 0

assert proxy_domain_client.metadata == domain_client.metadata
assert proxy_domain_client.user_role == ServiceRole.NONE

domain_client.login(email="[email protected]", password="changethis")
proxy_domain_client.login(email="[email protected]", password="changethis")

assert proxy_domain_client.logged_in_user == "[email protected]"
assert proxy_domain_client.user_role == ServiceRole.ADMIN
assert proxy_domain_client.credentials == domain_client.credentials
assert (
proxy_domain_client.api.endpoints.keys() == domain_client.api.endpoints.keys()
)
32 changes: 17 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -260,31 +260,30 @@ commands =
bash -c "docker volume rm test-domain-1_mongo-data --force || true"
bash -c "docker volume rm test-domain-1_credentials-data --force || true"
bash -c "docker volume rm test-domain-1_seaweedfs-data --force || true"
bash -c "docker volume rm test-domain-2_mongo-data --force || true"
bash -c "docker volume rm test-domain-2_credentials-data --force || true"
bash -c "docker volume rm test-domain-2_seaweedfs-data --force || true"
bash -c "docker volume rm test-domain-1_tailscale-data --force || true"
; bash -c "docker volume rm test-domain-2_mongo-data --force || true"
; bash -c "docker volume rm test-domain-2_credentials-data --force || true"
; bash -c "docker volume rm test-domain-2_seaweedfs-data --force || true"
; bash -c "docker volume rm test-domain-2_tailscale-data --force || true"
bash -c "docker volume rm test-gateway-1_mongo-data --force || true"
bash -c "docker volume rm test-gateway-1_credentials-data --force || true"
bash -c "docker volume rm test-gateway-1_seaweedfs-data --force || true"

bash -c "docker volume rm test-domain-1_tailscale-data --force || true"
bash -c "docker volume rm test-domain-2_tailscale-data --force || true"
bash -c "docker volume rm test-gateway-1_tailscale-data --force || true"
bash -c "docker volume rm test-gateway-1_headscale-data --force || true"

python -c 'import syft as sy; sy.stage_protocol_changes()'

bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test_gateway_1 network to docker:9081 $HAGRID_FLAGS --no-health-checks --verbose --no-warnings --dev'
bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test_domain_1 domain to docker:9082 $HAGRID_FLAGS --no-health-checks --enable-signup --verbose --no-warnings --dev'
bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test_domain_2 domain to docker:9083 --headless $HAGRID_FLAGS --enable-signup --no-health-checks --verbose --no-warnings --dev'
bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test-gateway-1 network to docker:9081 $HAGRID_FLAGS --no-health-checks --verbose --no-warnings --dev'
bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test-domain-1 domain to docker:9082 $HAGRID_FLAGS --no-health-checks --enable-signup --verbose --no-warnings --dev'
; bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test-domain-2 domain to docker:9083 --headless $HAGRID_FLAGS --enable-signup --no-health-checks --verbose --no-warnings --dev'

; wait for nodes to start
docker ps
bash -c "echo Waiting for Nodes; date"
bash -c '(docker logs test_domain_1-frontend-1 -f &) | grep -q -E "Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/" || true'
bash -c '(docker logs test_domain_1-backend-1 -f &) | grep -q "Application startup complete" || true'
bash -c '(docker logs test_domain_2-backend-1 -f &) | grep -q "Application startup complete" || true'
bash -c '(docker logs test_gateway_1-backend-1 -f &) | grep -q "Application startup complete" || true'
bash -c '(docker logs test-domain-1-frontend-1 -f &) | grep -q -E "Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/" || true'
bash -c '(docker logs test-domain-1-backend-1 -f &) | grep -q "Application startup complete" || true'
; bash -c '(docker logs test_domain_2-backend-1 -f &) | grep -q "Application startup complete" || true'
bash -c '(docker logs test-gateway-1-backend-1 -f &) | grep -q "Application startup complete" || true'

; frontend
bash -c 'if [[ "$PYTEST_MODULES" == *"frontend"* ]]; then \
Expand Down Expand Up @@ -651,7 +650,7 @@ commands =
cd packages/grid && \
(r=5;while ! \
devspace --no-warn --kube-context "k3d-$NODE_NAME" --namespace $NODE_NAME \
--var DOMAIN_NAME=$NODE_NAME \
--var NODE_NAME=$NODE_NAME \
--var NETWORK_CHECK_INTERVAL=5 \
--var ASSOCIATION_TIMEOUT=100 \
--var TEST_MODE=1 \
Expand All @@ -669,7 +668,7 @@ commands =
cd packages/grid && \
(r=5;while ! \
devspace --no-warn --kube-context "k3d-$NODE_NAME" --namespace $NODE_NAME \
--var DOMAIN_NAME=$NODE_NAME \
--var NODE_NAME=$NODE_NAME \
--var DOMAIN_CHECK_INTERVAL=5 \
--var ASSOCIATION_TIMEOUT=100 \
--var TEST_MODE=1 \
Expand Down Expand Up @@ -753,6 +752,9 @@ commands =
# Run 0.8 notebooks
pytest --nbmake notebooks/api/0.8 -p no:randomly -vvvv -k 'not 06'

#Integration + Gateway Connection Tests
pytest tests/integration/network -p no:randomly -vvvv

# deleting clusters created
bash -c "k3d cluster delete test-gateway-1 || true"
bash -c "k3d cluster delete test-domain-1 || true"
Expand Down

0 comments on commit b6dc962

Please sign in to comment.