altangent / ccxws

WebSocket client for 38 cryptocurrency exchanges
MIT License
617 stars 186 forks source link

general: refactor tests to use task parallelism #206

Closed bmancini55 closed 3 years ago

bmancini55 commented 4 years ago

Tests currently execute in parallel using the mocha-parallel-tests library. Integration tests often have errors due to lulls in less liquid exchanges. It would be nice to use parallelism in circleci so that we only need to rerun exchanges that have failed. We probably want to use workflows to run each exchange as a job: https://circleci.com/docs/2.0/workflows/.

Likely the biggest challenge is going to be coverage reporting. This is currently handled by nyc and pushed to coveralls which does support parallel merges https://docs.coveralls.io/parallel-build-webhook

bmancini55 commented 4 years ago

Very rudimentary sample of workflow parallelism. Probably can reduce the copy-pasta with Orbs. The done job is a placeholder for the coveralls webhook.

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      - run: npm install
      - persist_to_workspace:
          root: ~/repo
          paths: node_modules

  test_bibox:
    docker:
      - image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run:
          command: |-
            $(npm bin)/mocha __tests__/exchanges/bibox-client.spec.js

  test_binance:
    docker:
      - image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run:
          command: |-
            $(npm bin)/mocha __tests__/exchanges/binance-client.spec.js

  test_binancefcm:
    docker:
      - image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run:
          command: |-
            $(npm bin)/mocha __tests__/exchanges/binance-futures-coinm-client.spec.js

  test_binancefum:
    docker:
      - image: circleci/node:10
    working_directory: ~/repo
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run:
          command: |-
            $(npm bin)/mocha __tests__/exchanges/binance-futures-usdtm-client.spec.js

  done:
    docker:
      - image: circleci/buildpack-deps:curl-browsers
    steps:
      - run:
          command: echo "Hello ${CIRCLE_USERNAME}"
      - run:
          name: Show some of the CircleCI runtime env vars
          command: |-
            echo "TRIGGERER: ${CIRCLE_USERNAME}"
            echo "BUILD_NUMBER: ${CIRCLE_BUILD_NUM}"
            echo "BUILD_URL: ${CIRCLE_BUILD_URL}"
            echo "BRANCH: ${CIRCLE_BRANCH}"
            echo "RUNNING JOB: ${CIRCLE_JOB}"
            echo "JOB PARALLELISM: ${CIRCLE_NODE_TOTAL}"
            echo "CIRCLE_REPOSITORY_URL: ${CIRCLE_REPOSITORY_URL}"

workflows:
  version: 2
  test_all:
    jobs:
      - build
      - test_bibox:
          requires: [build]
      - test_binance:
          requires: [build]
      - test_binancefcm:
          requires: [build]
      - test_binancefum:
          requires: [build]
      - done:
          requires:
            - test_bibox
            - test_binance
            - test_binancefcm
            - test_binancefum