Skip to content

Commit

Permalink
Enable server acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-ifak committed Nov 12, 2024
1 parent dc6d01a commit 889b0c0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on: [push]
jobs:
build:
runs-on: ubuntu-latest
# services:
# aasx-server:
# image: adminshellio/aasx-server-blazor-for-demo:main
steps:
- uses: actions/checkout@v4
with:
Expand Down
1 change: 1 addition & 0 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ coverage run \

PYTHONPATH=. ./test/acceptance/file.py
PYTHONPATH=. ./test/acceptance/generate.py
PYTHONPATH=. ./test/acceptance/server.py
85 changes: 73 additions & 12 deletions test/acceptance/server.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,80 @@
#! /usr/bin/env python3

from aas_test_engines import api
import sys
import os
import subprocess
import atexit
import requests
import time
from dataclasses import dataclass

conf = api.ExecConf(
server=sys.argv[1] if len(sys.argv) == 2 else 'http://aasx-server:5001/api/v3.0',
)
HOST = 'http://localhost:5001'
script_dir = os.path.dirname(os.path.realpath(__file__))

result_aas_repo, mat = api.execute_tests(conf, "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRepositoryServiceSpecification/SSP-002")
result_aas_repo.dump()
mat.print()

result_submodel_repo, mat = api.execute_tests(conf, "https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-002")
result_submodel_repo.dump()
mat.print()
def wait_for_server(url: str, max_tries=10):
for _ in range(max_tries):
try:
requests.get(url, verify=False)
print(f"Server is up at {url}")
return
except requests.exceptions.ConnectionError:
pass
time.sleep(1)
print(f"Cannot reach server at {url}")

assert result_aas_repo.ok()
assert result_submodel_repo.ok()

def start_server() -> str:
container_id = subprocess.check_output([
'docker', 'run',
'--publish', '5001:5001',
'--detach',
'--volume', f'{script_dir}/../../bin/check_servers/test_data:/AasxServerBlazor/aasxs',
'docker.io/adminshellio/aasx-server-blazor-for-demo:main',
])
return container_id.decode().strip()


def stop_server(container_id: str):
print(f"Stopping {container_id}")
subprocess.check_output([
'docker', 'kill', container_id
])


def show_server_logs(container_id: str):
subprocess.check_call([
'docker', 'logs', container_id
])


container_id = start_server()
atexit.register(lambda: stop_server(container_id))
wait_for_server(HOST)
show_server_logs(container_id)


@dataclass
class Params:
url: str
suite: str


params = [
Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRepositoryServiceSpecification/SSP-002"),
Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-002"),
# Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellServiceSpecification/SSP-002"),
# Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-002"),
]

for param in params:
print("-"*10)
print(f"Checking {param.suite}")
conf = api.ExecConf(
server=f"{HOST}{param.url}"
)
result, mat = api.execute_tests(conf, param.suite)
mat.print()
assert result.ok()
assert mat.valid_rejected == 0
assert mat.invalid_accepted == 0

0 comments on commit 889b0c0

Please sign in to comment.