You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2020/07/01 06:39:00 UTC

[skywalking-python] branch master updated: Polish the test framework for simplicity of local test (#28)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git


The following commit(s) were added to refs/heads/master by this push:
     new 26879f8  Polish the test framework for simplicity of local test (#28)
26879f8 is described below

commit 26879f836212497d7f6c019088bb54915f40c03c
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Jul 1 14:37:58 2020 +0800

    Polish the test framework for simplicity of local test (#28)
    
    - 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
---
 .../docker-compose.base.yml}                       | 41 +++------------------
 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 ++++++----------------
 tests/plugin/sw_http_wsgi/services/consumer.py     |  1 -
 tests/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, 40 insertions(+), 139 deletions(-)

diff --git a/tests/plugin/sw_http/docker-compose.yml b/tests/plugin/docker/docker-compose.base.yml
similarity index 59%
copy from tests/plugin/sw_http/docker-compose.yml
copy to tests/plugin/docker/docker-compose.base.yml
index 3f0d305..852f0fb 100644
--- a/tests/plugin/sw_http/docker-compose.yml
+++ b/tests/plugin/docker/docker-compose.base.yml
@@ -20,7 +20,7 @@ version: '2.1'
 services:
   collector:
     build:
-      context: ../docker
+      context: .
       dockerfile: Dockerfile.tool
     ports:
       - 19876:19876
@@ -33,46 +33,13 @@ services:
       timeout: 60s
       retries: 120
 
-  provider:
+  agent:
     build:
       context: ../../../
       dockerfile: tests/plugin/docker/Dockerfile.agent
-    networks:
-      - beyond
-    ports:
-      - 9091:9091
-    volumes:
-      - ./services/provider.py:/app/provider.py
     environment:
       SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876
-    command: ['python3', '/app/provider.py']
-    depends_on:
-      collector:
-        condition: service_healthy
-    healthcheck:
-      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9091"]
-      interval: 5s
-      timeout: 60s
-      retries: 120
-
-  consumer:
-    build:
-      context: ../../../
-      dockerfile: tests/plugin/docker/Dockerfile.agent
+      SW_AGENT_LOGGING_LEVEL: DEBUG
     networks:
       - beyond
-    ports:
-      - 9090:9090
-    volumes:
-      - ./services/consumer.py:/app/consumer.py
-    environment:
-      SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876
-    command: ['python3', '/app/consumer.py']
-    depends_on:
-      collector:
-        condition: service_healthy
-      provider:
-        condition: service_healthy
-
-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 3f0d305..4233f03 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 43f60bd..e0d59bf 100644
--- a/tests/plugin/sw_http/services/consumer.py
+++ b/tests/plugin/sw_http/services/consumer.py
@@ -21,7 +21,6 @@ from skywalking import agent, config
 
 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 7af884a..3cdd5f2 100644
--- a/tests/plugin/sw_http/services/provider.py
+++ b/tests/plugin/sw_http/services/provider.py
@@ -21,7 +21,6 @@ from skywalking import agent, config
 
 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 eacaa98..856db04 100644
--- a/tests/plugin/sw_http/test_http.py
+++ b/tests/plugin/sw_http/test_http.py
@@ -26,7 +26,7 @@ from testcontainers.compose import DockerCompose
 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 3f0d305..4233f03 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 43f60bd..e0d59bf 100644
--- a/tests/plugin/sw_http_wsgi/services/consumer.py
+++ b/tests/plugin/sw_http_wsgi/services/consumer.py
@@ -21,7 +21,6 @@ from skywalking import agent, config
 
 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 a8c4b84..93433c2 100644
--- a/tests/plugin/sw_http_wsgi/services/provider.py
+++ b/tests/plugin/sw_http_wsgi/services/provider.py
@@ -21,7 +21,6 @@ from skywalking import agent, config
 
 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 eacaa98..856db04 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 testcontainers.compose import DockerCompose
 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 3f0d305..4233f03 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 4328fc1..6681ac9 100644
--- a/tests/plugin/sw_requests/services/consumer.py
+++ b/tests/plugin/sw_requests/services/consumer.py
@@ -21,7 +21,6 @@ from skywalking import agent, config
 
 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 7af884a..3cdd5f2 100644
--- a/tests/plugin/sw_requests/services/provider.py
+++ b/tests/plugin/sw_requests/services/provider.py
@@ -21,7 +21,6 @@ from skywalking import agent, config
 
 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 eacaa98..856db04 100644
--- a/tests/plugin/sw_requests/test_request.py
+++ b/tests/plugin/sw_requests/test_request.py
@@ -26,7 +26,7 @@ from testcontainers.compose import DockerCompose
 from tests.plugin import BasePluginTest
 
 
-class TestRequestPlugin(BasePluginTest):
+class TestPlugin(BasePluginTest):
     @classmethod
     def setUpClass(cls):
         cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))