Skip to content

Commit

Permalink
test: fix further tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joan Fontanals Martinez <[email protected]>
  • Loading branch information
JoanFM committed Jul 14, 2023
1 parent 855a5fe commit 4da6635
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 56 deletions.
92 changes: 85 additions & 7 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ jobs:
JINAHUB_PASSWORD: ${{ secrets.JINAHUB_PASSWORD }}

k8s-flow-test:
needs: update-schema
needs: [lint-flake-8, code-injection]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand Down Expand Up @@ -576,8 +576,8 @@ jobs:
flags: ${{ steps.test.outputs.codecov_flag }}
fail_ci_if_error: false

k8s-graceful-and-deployment-test:
needs: update-schema
k8s-deployment-test:
needs: [lint-flake-8, code-injection]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand All @@ -596,11 +596,11 @@ jobs:
export JINA_LOG_LEVEL="ERROR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test graceful request handling on k8s and Executor deployment on k8s
- name: Test k8s Flow
run: |
export LINKERD2_VERSION=stable-2.11.4
curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_deployment.py ./tests/k8s/test_k8s_graceful_request_handling.py
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_deployment.py
timeout-minutes: 30
- name: Check codecov file
id: check_files
Expand All @@ -616,9 +616,49 @@ jobs:
flags: ${{ steps.test.outputs.codecov_flag }}
fail_ci_if_error: false

k8s-graceful-test:
needs: [lint-flake-8, code-injection]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Prepare enviroment
run: |
docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
python -m pip install --upgrade pip
python -m pip install wheel
pip install ".[all]" --no-cache-dir
pip install docarray==0.21.0
jina
export JINA_LOG_LEVEL="ERROR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test graceful request handling on k8s and Executor deployment on k8s
run: |
export LINKERD2_VERSION=stable-2.11.4
curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_graceful_request_handling.py
timeout-minutes: 45
- name: Check codecov file
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "coverage.xml"
- name: Upload coverage from test to Codecov
uses: codecov/[email protected]
if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
with:
file: coverage.xml
name: ${{ matrix.test-path }}-codecov
flags: ${{ steps.test.outputs.codecov_flag }}
fail_ci_if_error: false

k8s-failures-test:
needs: [ lint-flake-8, code-injection ]
runs-on: ubuntu-latest
needs: update-schema
steps:
- uses: actions/[email protected]
- name: Set up Python 3.8
Expand All @@ -642,6 +682,44 @@ jobs:
curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
curl --proto '=https' --tlsv1.2 -sSfL https://linkerd.github.io/linkerd-smi/install | sh
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_failures.py
timeout-minutes: 45
- name: Check codecov file
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "coverage.xml"
- name: Upload coverage from test to Codecov
uses: codecov/[email protected]
if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
with:
file: coverage.xml
name: ${{ matrix.test-path }}-codecov
flags: ${{ steps.test.outputs.codecov_flag }}
fail_ci_if_error: false

k8s-otel-test:
needs: [lint-flake-8, code-injection]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Prepare enviroment
run: |
docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
python -m pip install --upgrade pip
python -m pip install wheel
pip install ".[all]" --no-cache-dir
pip install docarray==0.21.0
jina
export JINA_LOG_LEVEL="ERROR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test k8s
run: |
pytest -v -s --cov=jina --cov-report=xml ./tests/k8s_otel
timeout-minutes: 30
- name: Check codecov file
id: check_files
Expand Down Expand Up @@ -717,7 +795,7 @@ jobs:
# just for blocking the merge until all parallel core-test are successful
success-all-steps:
runs-on: ubuntu-latest
needs: [core-test, docarray-v-two-test, import-test, hub-test, k8s-flow-test, k8s-graceful-and-deployment-test, k8s-failures-test, docker-compose-test, docker-image-test, benchmark-pre-release, update-schema, update-docker, pre-release]
needs: [core-test, docarray-v-two-test, import-test, hub-test, k8s-flow-test, k8s-deployment-test, k8s-graceful-test, k8s-failures-test, k8s-otel-test, docker-compose-test, docker-image-test, benchmark-pre-release, update-schema, update-docker, pre-release]
if: always()
steps:
- uses: technote-space/workflow-conclusion-action@v2
Expand Down
46 changes: 43 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,47 @@ jobs:
flags: ${{ steps.test.outputs.codecov_flag }}
fail_ci_if_error: false

k8s-graceful-and-deployment-test:
k8s-deployment-test:
needs: [lint-flake-8, code-injection]
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Prepare enviroment
run: |
docker build --build-arg DOCARRAY_VERSION="0.21.0" -f Dockerfiles/test-pip.Dockerfile -t jinaai/jina:test-pip .
python -m pip install --upgrade pip
python -m pip install wheel
pip install ".[all]" --no-cache-dir
pip install docarray==0.21.0
jina
export JINA_LOG_LEVEL="ERROR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test k8s Flow
run: |
export LINKERD2_VERSION=stable-2.11.4
curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_deployment.py
timeout-minutes: 30
- name: Check codecov file
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "coverage.xml"
- name: Upload coverage from test to Codecov
uses: codecov/[email protected]
if: steps.check_files.outputs.files_exists == 'true' && ${{ matrix.python-version }} == '3.8'
with:
file: coverage.xml
name: ${{ matrix.test-path }}-codecov
flags: ${{ steps.test.outputs.codecov_flag }}
fail_ci_if_error: false

k8s-graceful-test:
needs: [lint-flake-8, code-injection]
runs-on: ubuntu-latest
steps:
Expand All @@ -234,7 +274,7 @@ jobs:
run: |
export LINKERD2_VERSION=stable-2.11.4
curl --proto '=https' --tlsv1.2 -sSfL https://run.linkerd.io/install | sh
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_deployment.py ./tests/k8s/test_k8s_graceful_request_handling.py
pytest -v -s --suppress-no-test-exit-code --force-flaky --min-passes 1 --max-runs 5 --cov=jina --cov-report=xml ./tests/k8s/test_k8s_graceful_request_handling.py
timeout-minutes: 45
- name: Check codecov file
id: check_files
Expand Down Expand Up @@ -717,7 +757,7 @@ jobs:
# just for blocking the merge until all parallel core-test are successful
success-all-test:
runs-on: ubuntu-latest
needs: [commit-lint, core-test, docarray-v-two-test, import-test, hub-test, k8s-flow-test, k8s-failures-test, docker-compose-test, docker-image-test, check-docstring, check-black, code-injection, build-wheels]
needs: [commit-lint, core-test, docarray-v-two-test, import-test, hub-test, k8s-flow-test, k8s-deployment-test, k8s-graceful-test, k8s-failures-test, k8s-otel-test, docker-compose-test, docker-image-test, check-docstring, check-black, code-injection, build-wheels]

if: always()
steps:
Expand Down
52 changes: 19 additions & 33 deletions tests/k8s/test_k8s_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import pytest
from docarray import DocumentArray
from pytest_kind import cluster
from jina.serve.networking import GrpcConnectionPool
from jina.serve.runtimes.servers import BaseServer

from jina import Deployment
from jina import Deployment, Client
from jina.helper import random_port
from tests.k8s.conftest import shell_portforward

Expand Down Expand Up @@ -220,8 +222,7 @@ async def test_deployment_with_multiple_protocols(
dep = Deployment(
name='test-executor',
uses=f'docker://{docker_images[0]}',
shards=shards,
protocol=['gprc', 'http'],
protocol=['grpc', 'http'],
)

dump_path = os.path.join(
Expand All @@ -239,40 +240,25 @@ async def test_deployment_with_multiple_protocols(
deployment_replicas_expected=deployment_replicas_expected,
logger=logger,
)
grpc_port = GrpcConnectionPool.K8S_PORT
http_port = GrpcConnectionPool.K8S_PORT + 1

dump_path = os.path.join(str(tmpdir), 'k8s-multiprotocol-deployment')
namespace = 'flow-multiprotocol-gateway-builtin'

gateway_pod_name = (
core_client.list_namespaced_pod(
namespace=namespace, label_selector='app=gateway'
)
.items[0]
.metadata.name
)

# test portforwarding the gateway pod and service using http
forward_args = [
[gateway_pod_name, http_port, http_port, namespace],
['service/gateway', http_port, http_port, namespace],
'service/test-executor-1-http', http_port, http_port, namespace,
]
for forward in forward_args:
with shell_portforward(k8s_cluster._cluster.kubectl_path, *forward):
import requests

resp = requests.get(f'http://localhost:{http_port}').json()
assert resp == {}
# test portforwarding the gateway pod and service using grpc
forward_args = [
[gateway_pod_name, grpc_port, grpc_port, namespace],
['service/gateway-1-grpc', grpc_port, grpc_port, namespace],
]
for forward in forward_args:
with shell_portforward(k8s_cluster._cluster.kubectl_path, *forward):
grpc_client = Client(protocol='grpc', port=grpc_port, asyncio=True)
async for _ in grpc_client.post('/', inputs=DocumentArray.empty(5)):
pass
assert BaseServer.is_ready(f'localhost:{grpc_port}')
with shell_portforward(k8s_cluster._cluster.kubectl_path, *forward_args):
import requests

resp = requests.get(f'http://localhost:{http_port}').json()
assert resp == {}
forward_args = ['service/test-executor', grpc_port, grpc_port, namespace],

with shell_portforward(k8s_cluster._cluster.kubectl_path, *forward_args):
grpc_client = Client(protocol='grpc', port=grpc_port, asyncio=True)
async for _ in grpc_client.post('/', inputs=DocumentArray.empty(5)):
pass
assert BaseServer.is_ready(f'localhost:{grpc_port}')
except Exception as exc:
logger.error(f' Exception raised {exc}')
raise exc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_parse_args(
else:
assert (
deployment_config.services_args['head_service'].uses_before_address
== 'executor-uses-before:8078'
== 'executor-uses-before:8081'
)
if uses_after is None:
assert (
Expand All @@ -119,11 +119,11 @@ def test_parse_args(
else:
assert (
deployment_config.services_args['head_service'].uses_after_address
== 'executor-uses-after:8078'
== 'executor-uses-after:8081'
)
if replicas == 1:
candidate_connection_list = {
str(i): [f'executor-{i}:8078'] for i in range(shards)
str(i): [f'executor-{i}:8081'] for i in range(shards)
}
else:
candidate_connection_list = {}
Expand Down Expand Up @@ -654,7 +654,7 @@ def _mock_fetch(
assert '--name' in replica_args
assert replica_args[replica_args.index('--name') + 1] == expected_arg_name
assert '--port' in replica_args
assert replica_args[replica_args.index('--port') + 1] == '8078'
assert replica_args[replica_args.index('--port') + 1] == '8081'
assert '--env' not in replica_args
assert '--connection-list' not in replica_args
if uses_with is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ def _mock_fetch(
actual_port = spec_service['ports'][0]
assert actual_port['name'] == 'port'
assert actual_port['protocol'] == 'TCP'
assert actual_port['port'] == int(GRPCConnectionPool.K8S_PORT) + i
assert actual_port['targetPort'] == int(GRPCConnectionPool.K8S_PORT) + i
assert actual_port['port'] == int(GrpcConnectionPool.K8S_PORT) + i
assert actual_port['targetPort'] == int(GrpcConnectionPool.K8S_PORT) + i
assert spec_service['selector'] == {'app': 'gateway'}

assert spec_service['selector'] == {'app': 'gateway'}
Expand Down Expand Up @@ -445,7 +445,7 @@ def _mock_fetch(
assert args[args.index('--k8s-namespace') + 1] == 'default-namespace'
assert '--port' in args
for i, _port in enumerate(port):
assert args[args.index('--port') + i + 1] == str(GRPCConnectionPool.K8S_PORT + i)
assert args[args.index('--port') + i + 1] == str(GrpcConnectionPool.K8S_PORT + i)
assert '--env' not in args
if deployments_addresses is not None:
assert '--deployments-addresses' in args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_flow_to_docker_compose_yaml(tmpdir, protocol):
assert '--deployments-addresses' in gateway_args
assert (
gateway_args[gateway_args.index('--deployments-addresses') + 1]
== '{"executor0": ["executor0:8078"], "executor1": ["executor1-head:8078"], "executor2": ["executor2-head:8078"]}'
== '{"executor0": ["executor0:8081"], "executor1": ["executor1-head:8081"], "executor2": ["executor2-head:8081"]}'
)
if protocol == 'http':
assert '--protocol' in gateway_args
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_flow_to_docker_compose_yaml(tmpdir, protocol):
assert '--connection-list' in executor1_head_args
assert (
executor1_head_args[executor1_head_args.index('--connection-list') + 1]
== '{"0": ["executor1-0:8078"], "1": ["executor1-1:8078"]}'
== '{"0": ["executor1-0:8081"], "1": ["executor1-1:8081"]}'
)
assert '--uses-with' not in executor1_head_args
assert '--uses-before' not in executor1_head_args
Expand Down Expand Up @@ -192,9 +192,9 @@ def test_flow_to_docker_compose_yaml(tmpdir, protocol):
assert '--native' in executor2_head_args
assert '--connection-list' in executor2_head_args
assert executor2_head_args[executor2_head_args.index('--connection-list') + 1] == (
'{"0": ["executor2-0-rep-0:8078", "executor2-0-rep-1:8078"],'
'{"0": ["executor2-0-rep-0:8081", "executor2-0-rep-1:8081"],'
' "1": '
'["executor2-1-rep-0:8078", "executor2-1-rep-1:8078"]}'
'["executor2-1-rep-0:8081", "executor2-1-rep-1:8081"]}'
)
assert '--uses-with' not in executor2_head_args
assert '--uses-before' not in executor2_head_args
Expand All @@ -203,12 +203,12 @@ def test_flow_to_docker_compose_yaml(tmpdir, protocol):
assert '--uses-before-address' in executor2_head_args
assert (
executor2_head_args[executor2_head_args.index('--uses-before-address') + 1]
== 'executor2-uses-before:8078'
== 'executor2-uses-before:8081'
)
assert '--uses-after-address' in executor2_head_args
assert (
executor2_head_args[executor2_head_args.index('--uses-after-address') + 1]
== 'executor2-uses-after:8078'
== 'executor2-uses-after:8081'
)

executor2_0_rep_0_service = services['executor2-0-rep-0']
Expand Down

0 comments on commit 4da6635

Please sign in to comment.