Skip to content

Commit

Permalink
test_: graceful shutdown for codecov, logs from each container
Browse files Browse the repository at this point in the history
  • Loading branch information
antdanchenko committed Dec 10, 2024
1 parent e78d3a7 commit 7947ca5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ internal/version/GIT_COMMIT
internal/sentry/SENTRY_CONTEXT_NAME
internal/sentry/SENTRY_CONTEXT_VERSION
internal/sentry/SENTRY_PRODUCTION
logs-*

# Don't ignore generated files in the vendor/ directory
!vendor/**/*.pb.go
Expand Down
1 change: 1 addition & 0 deletions _assets/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RUN ln -s /usr/local/bin/$build_target /usr/local/bin/entrypoint

# 30304 is used for Discovery v5
EXPOSE 8080 8545 30303 30303/udp 30304/udp
STOPSIGNAL SIGINT

ENTRYPOINT ["/usr/local/bin/entrypoint"]
CMD ["--help"]
38 changes: 30 additions & 8 deletions tests-functional/clients/status_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import threading
import requests
import docker
import os

from tenacity import retry, stop_after_delay, wait_fixed
from clients.signals import SignalClient
Expand All @@ -30,7 +31,6 @@ def __init__(self, await_signals=[], new_container=True):
else:
url = option.status_backend_url


self.api_url = f"{url}/statusgo"
self.ws_url = f"{url}".replace("http", "ws")
self.rpc_url = f"{url}/statusgo/CallRPC"
Expand All @@ -39,6 +39,7 @@ def __init__(self, await_signals=[], new_container=True):
SignalClient.__init__(self, self.ws_url, await_signals)

self._health_check()
input()

websocket_thread = threading.Thread(target=self._connect)
websocket_thread.daemon = True
Expand All @@ -51,6 +52,9 @@ def _start_container(self, host_port):
image_name = f"{docker_project_name}-status-backend:latest"
container_name = f"{docker_project_name}-status-backend-{timestamp}"

coverage_path = os.path.abspath("./coverage/binary")
init_folder = os.path.abspath(f"./logs-{container_name}")

container = self.docker_client.containers.run(
image_name,
detach=True,
Expand All @@ -60,10 +64,25 @@ def _start_container(self, host_port):
"status-backend",
"--address", "0.0.0.0:3333",
],
ports={"3333/tcp": host_port}
ports={"3333/tcp": host_port},
environment={
"GOCOVERDIR": "/coverage/binary",
},
volumes={
coverage_path: {
"bind": "/coverage/binary",
"mode": "rw",
},
init_folder: {
"bind": "/init_folder",
"mode": "rw",
},
},
stop_signal="SIGINT"
)

network = self.docker_client.networks.get(f"{docker_project_name}_default")
network = self.docker_client.networks.get(
f"{docker_project_name}_default")
network.connect(container)

option.status_backend_containers.append(container.id)
Expand All @@ -83,7 +102,8 @@ def _health_check(self):
def api_request(self, method, data, url=None):
url = url if url else self.api_url
url = f"{url}/{method}"
logging.info(f"Sending POST request to url {url} with data: {json.dumps(data, sort_keys=True, indent=4)}")
logging.info(
f"Sending POST request to url {url} with data: {json.dumps(data, sort_keys=True, indent=4)}")
response = requests.post(url, json=data)
logging.info(f"Got response: {response.content}")
return response
Expand All @@ -105,7 +125,7 @@ def api_valid_request(self, method, data):
self.verify_is_valid_api_response(response)
return response

def init_status_backend(self, data_dir="/"):
def init_status_backend(self, data_dir="/init_folder"):
method = "InitializeApplication"
data = {
"dataDir": data_dir,
Expand All @@ -128,7 +148,7 @@ def create_account_and_login(self, data_dir="/", display_name=DEFAULT_DISPLAY_NA
}
return self.api_valid_request(method, data)

def restore_account_and_login(self, data_dir="/",display_name=DEFAULT_DISPLAY_NAME, user=user_1,
def restore_account_and_login(self, data_dir="/init_folder", display_name=DEFAULT_DISPLAY_NAME, user=user_1,
network_id=31337):
method = "RestoreAccountAndLogin"
data = {
Expand Down Expand Up @@ -183,7 +203,8 @@ def restore_account_and_wait_for_rpc_client_to_start(self, timeout=60):
return
except AssertionError:
time.sleep(3)
raise TimeoutError(f"RPC client was not started after {timeout} seconds")
raise TimeoutError(
f"RPC client was not started after {timeout} seconds")

@retry(stop=stop_after_delay(10), wait=wait_fixed(0.5), reraise=True)
def start_messenger(self, params=[]):
Expand Down Expand Up @@ -220,7 +241,8 @@ def get_pubkey(self, display_name):
for account in accounts:
if account.get("name") == display_name:
return account.get("public-key")
raise ValueError(f"Public key not found for display name: {display_name}")
raise ValueError(
f"Public key not found for display name: {display_name}")

def send_contact_request(self, params=[]):
method = "wakuext_sendContactRequest"
Expand Down
2 changes: 1 addition & 1 deletion tests-functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def pytest_unconfigure():
for container_id in option.status_backend_containers:
try:
container = docker_client.containers.get(container_id)
container.stop()
container.stop(timeout=30)
container.remove()
except Exception as e:
print(e)

0 comments on commit 7947ca5

Please sign in to comment.