减少python测试阶段的管道执行时间

时间:2021-02-21 11:15:15

标签: python django docker-compose google-cloud-build pytest-xdist

感谢您的支持,因为我需要减少运行 python 测试用例的管道执行时间

通过我的本地机器需要 3 分钟或更短时间,但通过管道机器需要 8 分钟或更长时间

本地机器

处理器 Intel(R) Core(TM) i7-4510U CPU @ 2.00GHz

内存 16GiB 系统内存

Cloudbuild 流水线机器

8 个 vCPU 8 Gib RAM

我使用以下命令来执行测试用例,但没有什么不同 所以我认为测试人员不能并行工作,8个cpu内核没有很好地使用 或者 docker-compose 步骤没有使用流水线机器的全部功能。

pytest -n 4
pytest -n 6 
pytest -n auto 

我的 docker-compose 文件

version: '3'
services:
  redis:
    image: registry.hub.docker.com/library/redis:latest
    expose:
        - 6379
  postgres:
    image: registry.hub.docker.com/library/postgres:9.6
    restart: always
    command: -c max_connections=3000 -c fsync=off -c synchronous_commit=off -c full_page_writes=off -c max_locks_per_transaction=500
    volumes:
        - ./postgres/pgdata:/var/lib/postgresql/data
    environment:
        - POSTGRES_PASSWORD=my-postgres-pass
        - POSTGRES_USER=my-postgres-user
        - POSTGRES_DB=my-postgres-db
    expose:
        - "5432"
  datastore:
    image: registry.hub.docker.com/google/cloud-sdk
    entrypoint: bash
    command: gcloud beta emulators datastore start --host-port 0.0.0.0:8081
    environment:
        - CLOUDSDK_CORE_PROJECT=my-project
    expose:
        - "8081"
  pubsub:
    image: registry.hub.docker.com/google/cloud-sdk
    entrypoint: bash
    command: gcloud beta emulators pubsub start --host-port 0.0.0.0:8085
    environment:
        - CLOUDSDK_CORE_PROJECT=my-project
    expose:
        - "8085"
  django:
    working_dir: /opt/my-project
    image: $GUNICORN_IMAGE_NAME
    entrypoint: bash
    command: >
        -c "
        /usr/local/bin/pip install -r /opt/my-project/requirements.dev.txt &&
        python manage.py migrate_schemas &&
        pytest -n auto ."
    depends_on:
        - postgres
        - redis
        - datastore
        - pubsub
    environment:
        ......

我的云构建文件

- name: "gcr.io/cloud-builders/docker"
  id: 'gunicorn_build'
  args: ['build', '-t', 'gcr.io/${PROJECT_ID}/${REPO_NAME}-gunicorn:${BRANCH_NAME}-${SHORT_SHA}', '.']


- name: 'gcr.io/$PROJECT_ID/docker-compose'
  id: 'test_cases'
  args: ['-f','./docker/docker-compose.yml','up', '--abort-on-container-exit' , '--exit-code-from', 'django' ]
  env:
  - 'GUNICORN_IMAGE_NAME=gcr.io/${PROJECT_ID}/${REPO_NAME}-gunicorn:${BRANCH_NAME}-${SHORT_SHA}'


options:
  machineType: 'E2_HIGHCPU_8'

0 个答案:

没有答案
相关问题