Skip to content

Commit

Permalink
Disable ray in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raffomania committed Nov 2, 2023
1 parent 0d96d08 commit a32aa4f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/backend_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ jobs:
run-unit-tests:
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false
- name: Set Swap Space to 10GB
uses: pierotofy/set-swap-space@master
with:
Expand All @@ -82,7 +67,7 @@ jobs:
export RAY_CONFIG="./config_test_no_gpu.yaml"
docker compose -f compose-test.yml up -d --quiet-pull
echo Waiting for containers to start...
sleep 240
sleep 30
cd ..
- name: Run CRUD tests
run: |
Expand Down
1 change: 1 addition & 0 deletions backend/src/app/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __init_services__(
from app.preprocessing.ray_model_service import RayModelService

RayModelService()

# import and init SimSearchService
from app.core.search.simsearch_service import SimSearchService

Expand Down
19 changes: 13 additions & 6 deletions backend/src/app/preprocessing/ray_model_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import Any, Dict, List

import requests
Expand Down Expand Up @@ -28,6 +29,11 @@

class RayModelService(metaclass=SingletonMeta):
def __new__(cls, *args, **kwargs):
running_in_test = hasattr(sys, "_called_from_test")
if running_in_test:
# When running in tests, don't use the ray service at all
return super(RayModelService, cls).__new__(cls)

cls.base_url = f"{conf.ray.protocol}://" f"{conf.ray.host}:" f"{conf.ray.port}"
logger.info(f"RayModelService base_url: {cls.base_url}")

Expand All @@ -41,17 +47,18 @@ def __new__(cls, *args, **kwargs):
)
logger.error(msg)
raise Exception(msg)

cls.base_routes: List[str] = list(response.json().keys())
logger.info(
f"RayModelService detected the following base routes:"
f"\n{cls.base_routes}"
)

except Exception as e:
msg = f"Error while starting the RayModelService! Exception: {str(e)}"
logger.error(msg)
raise SystemExit(msg)

cls.base_routes: List[str] = list(response.json().keys())
logger.info(
f"RayModelService detected the following base routes:"
f"\n{cls.base_routes}"
)

return super(RayModelService, cls).__new__(cls)

def _assert_valid_base_route(self, endpoint: str) -> None:
Expand Down
7 changes: 6 additions & 1 deletion backend/src/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
import random
import string

# Allow app to detect if it's running inside tests
import sys

import pytest
from app.core.startup import startup

sys._called_from_test = True

# Flo: just do it once. We have to check because if we start the main function, unvicorn will import this
# file once more manually, so it would be executed twice.
STARTUP_DONE = bool(int(os.environ.get("STARTUP_DONE", "0")))
if not STARTUP_DONE:
startup(reset_data=True)
startup(reset_data=True, enable_ray=False)
os.environ["STARTUP_DONE"] = "1"

from app.core.data.crud.code import crud_code
Expand Down
8 changes: 7 additions & 1 deletion docker/monkey_patch_docker_compose_for_backend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
with open("docker-compose.yml") as f:
file = f.read()


data = yaml.safe_load(file)

# remove ray as it's too resource-intensive for CI
data["services"].pop("ray", None)
data["services"]["celery-background-jobs-worker"]["links"].remove("ray")
data["services"]["dwts-backend-api"]["depends_on"].remove("ray")
data["services"]["dwts-backend-api"]["links"].remove("ray")

for a in data["services"]:
data["services"][a].pop("deploy", None)

Expand Down

0 comments on commit a32aa4f

Please sign in to comment.