From 3a5c4550bd4bf869ade2f050810a0d8da1175147 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Wed, 1 Jul 2020 00:12:39 +0800 Subject: [PATCH] Polish the test framework for simplicity of local test - Extract as many commonly-used codes as possible - Rename the test class to a more general one as contributors tend to copy-paste w/o modifying the class name --- tests/plugin/docker/docker-compose.base.yml | 45 +++++++++++++++++++ tests/plugin/sw_http/docker-compose.yml | 42 +++++------------ tests/plugin/sw_http/services/consumer.py | 1 - tests/plugin/sw_http/services/provider.py | 1 - tests/plugin/sw_http/test_http.py | 2 +- tests/plugin/sw_http_wsgi/docker-compose.yml | 42 +++++------------ .../plugin/sw_http_wsgi/services/consumer.py | 1 - .../plugin/sw_http_wsgi/services/provider.py | 1 - tests/plugin/sw_http_wsgi/test_http_wsgi.py | 2 +- tests/plugin/sw_requests/docker-compose.yml | 42 +++++------------ tests/plugin/sw_requests/services/consumer.py | 1 - tests/plugin/sw_requests/services/provider.py | 1 - tests/plugin/sw_requests/test_request.py | 2 +- 13 files changed, 81 insertions(+), 102 deletions(-) create mode 100644 tests/plugin/docker/docker-compose.base.yml diff --git a/tests/plugin/docker/docker-compose.base.yml b/tests/plugin/docker/docker-compose.base.yml new file mode 100644 index 00000000..852f0fb9 --- /dev/null +++ b/tests/plugin/docker/docker-compose.base.yml @@ -0,0 +1,45 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +version: '2.1' + +services: + collector: + build: + context: . + dockerfile: Dockerfile.tool + ports: + - 19876:19876 + - 12800:12800 + networks: + - beyond + healthcheck: + test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"] + interval: 5s + timeout: 60s + retries: 120 + + agent: + build: + context: ../../../ + dockerfile: tests/plugin/docker/Dockerfile.agent + environment: + SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 + SW_AGENT_LOGGING_LEVEL: DEBUG + networks: + - beyond + command: ['python3', '/entrypoint.py'] diff --git a/tests/plugin/sw_http/docker-compose.yml b/tests/plugin/sw_http/docker-compose.yml index 3f0d3059..4233f03c 100644 --- a/tests/plugin/sw_http/docker-compose.yml +++ b/tests/plugin/sw_http/docker-compose.yml @@ -19,33 +19,18 @@ version: '2.1' services: collector: - build: - context: ../docker - dockerfile: Dockerfile.tool - ports: - - 19876:19876 - - 12800:12800 - networks: - - beyond - healthcheck: - test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"] - interval: 5s - timeout: 60s - retries: 120 + extends: + service: collector + file: ../docker/docker-compose.base.yml provider: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: agent + file: ../docker/docker-compose.base.yml ports: - 9091:9091 volumes: - - ./services/provider.py:/app/provider.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/provider.py'] + - ./services/provider.py:/entrypoint.py depends_on: collector: condition: service_healthy @@ -56,18 +41,13 @@ services: retries: 120 consumer: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: agent + file: ../docker/docker-compose.base.yml ports: - 9090:9090 volumes: - - ./services/consumer.py:/app/consumer.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/consumer.py'] + - ./services/consumer.py:/entrypoint.py depends_on: collector: condition: service_healthy diff --git a/tests/plugin/sw_http/services/consumer.py b/tests/plugin/sw_http/services/consumer.py index 43f60bda..e0d59bf9 100644 --- a/tests/plugin/sw_http/services/consumer.py +++ b/tests/plugin/sw_http/services/consumer.py @@ -21,7 +21,6 @@ if __name__ == '__main__': config.service_name = 'consumer' - config.logging_level = 'DEBUG' agent.start() import socketserver diff --git a/tests/plugin/sw_http/services/provider.py b/tests/plugin/sw_http/services/provider.py index 7af884ab..3cdd5f2e 100644 --- a/tests/plugin/sw_http/services/provider.py +++ b/tests/plugin/sw_http/services/provider.py @@ -21,7 +21,6 @@ if __name__ == '__main__': config.service_name = 'provider' - config.logging_level = 'DEBUG' agent.start() import socketserver diff --git a/tests/plugin/sw_http/test_http.py b/tests/plugin/sw_http/test_http.py index eacaa980..856db043 100644 --- a/tests/plugin/sw_http/test_http.py +++ b/tests/plugin/sw_http/test_http.py @@ -26,7 +26,7 @@ from tests.plugin import BasePluginTest -class TestRequestPlugin(BasePluginTest): +class TestPlugin(BasePluginTest): @classmethod def setUpClass(cls): cls.compose = DockerCompose(filepath=dirname(abspath(__file__))) diff --git a/tests/plugin/sw_http_wsgi/docker-compose.yml b/tests/plugin/sw_http_wsgi/docker-compose.yml index 3f0d3059..4233f03c 100644 --- a/tests/plugin/sw_http_wsgi/docker-compose.yml +++ b/tests/plugin/sw_http_wsgi/docker-compose.yml @@ -19,33 +19,18 @@ version: '2.1' services: collector: - build: - context: ../docker - dockerfile: Dockerfile.tool - ports: - - 19876:19876 - - 12800:12800 - networks: - - beyond - healthcheck: - test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"] - interval: 5s - timeout: 60s - retries: 120 + extends: + service: collector + file: ../docker/docker-compose.base.yml provider: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: agent + file: ../docker/docker-compose.base.yml ports: - 9091:9091 volumes: - - ./services/provider.py:/app/provider.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/provider.py'] + - ./services/provider.py:/entrypoint.py depends_on: collector: condition: service_healthy @@ -56,18 +41,13 @@ services: retries: 120 consumer: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: agent + file: ../docker/docker-compose.base.yml ports: - 9090:9090 volumes: - - ./services/consumer.py:/app/consumer.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/consumer.py'] + - ./services/consumer.py:/entrypoint.py depends_on: collector: condition: service_healthy diff --git a/tests/plugin/sw_http_wsgi/services/consumer.py b/tests/plugin/sw_http_wsgi/services/consumer.py index 43f60bda..e0d59bf9 100644 --- a/tests/plugin/sw_http_wsgi/services/consumer.py +++ b/tests/plugin/sw_http_wsgi/services/consumer.py @@ -21,7 +21,6 @@ if __name__ == '__main__': config.service_name = 'consumer' - config.logging_level = 'DEBUG' agent.start() import socketserver diff --git a/tests/plugin/sw_http_wsgi/services/provider.py b/tests/plugin/sw_http_wsgi/services/provider.py index a8c4b841..93433c21 100644 --- a/tests/plugin/sw_http_wsgi/services/provider.py +++ b/tests/plugin/sw_http_wsgi/services/provider.py @@ -21,7 +21,6 @@ if __name__ == '__main__': config.service_name = 'provider' - config.logging_level = 'DEBUG' agent.start() from werkzeug import Request, Response diff --git a/tests/plugin/sw_http_wsgi/test_http_wsgi.py b/tests/plugin/sw_http_wsgi/test_http_wsgi.py index eacaa980..856db043 100644 --- a/tests/plugin/sw_http_wsgi/test_http_wsgi.py +++ b/tests/plugin/sw_http_wsgi/test_http_wsgi.py @@ -26,7 +26,7 @@ from tests.plugin import BasePluginTest -class TestRequestPlugin(BasePluginTest): +class TestPlugin(BasePluginTest): @classmethod def setUpClass(cls): cls.compose = DockerCompose(filepath=dirname(abspath(__file__))) diff --git a/tests/plugin/sw_requests/docker-compose.yml b/tests/plugin/sw_requests/docker-compose.yml index 3f0d3059..4233f03c 100644 --- a/tests/plugin/sw_requests/docker-compose.yml +++ b/tests/plugin/sw_requests/docker-compose.yml @@ -19,33 +19,18 @@ version: '2.1' services: collector: - build: - context: ../docker - dockerfile: Dockerfile.tool - ports: - - 19876:19876 - - 12800:12800 - networks: - - beyond - healthcheck: - test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"] - interval: 5s - timeout: 60s - retries: 120 + extends: + service: collector + file: ../docker/docker-compose.base.yml provider: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: agent + file: ../docker/docker-compose.base.yml ports: - 9091:9091 volumes: - - ./services/provider.py:/app/provider.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/provider.py'] + - ./services/provider.py:/entrypoint.py depends_on: collector: condition: service_healthy @@ -56,18 +41,13 @@ services: retries: 120 consumer: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: agent + file: ../docker/docker-compose.base.yml ports: - 9090:9090 volumes: - - ./services/consumer.py:/app/consumer.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/consumer.py'] + - ./services/consumer.py:/entrypoint.py depends_on: collector: condition: service_healthy diff --git a/tests/plugin/sw_requests/services/consumer.py b/tests/plugin/sw_requests/services/consumer.py index 4328fc1d..6681ac9f 100644 --- a/tests/plugin/sw_requests/services/consumer.py +++ b/tests/plugin/sw_requests/services/consumer.py @@ -21,7 +21,6 @@ if __name__ == '__main__': config.service_name = 'consumer' - config.logging_level = 'DEBUG' agent.start() import socketserver diff --git a/tests/plugin/sw_requests/services/provider.py b/tests/plugin/sw_requests/services/provider.py index 7af884ab..3cdd5f2e 100644 --- a/tests/plugin/sw_requests/services/provider.py +++ b/tests/plugin/sw_requests/services/provider.py @@ -21,7 +21,6 @@ if __name__ == '__main__': config.service_name = 'provider' - config.logging_level = 'DEBUG' agent.start() import socketserver diff --git a/tests/plugin/sw_requests/test_request.py b/tests/plugin/sw_requests/test_request.py index eacaa980..856db043 100644 --- a/tests/plugin/sw_requests/test_request.py +++ b/tests/plugin/sw_requests/test_request.py @@ -26,7 +26,7 @@ from tests.plugin import BasePluginTest -class TestRequestPlugin(BasePluginTest): +class TestPlugin(BasePluginTest): @classmethod def setUpClass(cls): cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))