2

I want my integration tests to run in parallel on Circleci. I read this document https://circleci.com/blog/how-to-boost-build-time-with-test-parallelism/ and I setup my job like this

platform_component_test:
  working_directory: *workspace_root
  executor: ubuntu-machine
  parallelism: 16
  steps:
    - prepare_workspace
    - run:
        name: 'Run Platform Component tests'
        command:
          ./gradlew platform:componentTest -PtestFilter="`circleci tests glob "platform/src/componentTest/java/**/*.java"|circleci tests split`"

By looking at the UI, I see that each of the 16 containers that are spawn execute all the tests. Am I missing something?

Michele Da Ros
  • 856
  • 7
  • 21
  • 1
    If you followed the guide in the blog you referenced, you should have done some configuration around the testFilter property. Did you do that? In any case, isn't it easier to just use the [--tests](https://docs.gradle.org/current/userguide/java_testing.html#simple_name_pattern) parameter? – Bjørn Vester Feb 20 '20 at 12:34
  • 1
    indeed I had some problem in my gradle configuration. I'm currently trying to use the --tests option, looks like it works `./gradlew --build-cache platform:componentTest --tests "grep -ril 'platform/src/componentTest/java/' -e '@Test' | sed 's@.*/@@' | sed 's/\.[^.]*$//' | circleci tests split"` – Michele Da Ros Feb 20 '20 at 13:36
  • Did you ever figure this out? If so, can you post your solution? Asking for a friend... – Naruto Sempai May 22 '22 at 01:18

1 Answers1

1

I ended up slightly modifying this and incorporating what I learned from here and here to build this:

      - run:
          name: Run tests in parallel
          # Use "./gradlew test" instead if tests are not run in parallel
          command: |
            cd module-with-tests-to-run/src/test/kotlin
            # Get list of classnames of tests that should run on this node
            CLASSNAMES=$(circleci tests glob "**/**Test.kt" \
              | cut -c 1- | sed 's@/@.@g' \
              | sed 's/.\{3\}$//' \
              | circleci tests split --split-by=timings --timings-type=classname)
            cd ../../../..
            # Format the arguments to "./gradlew test"
            GRADLE_ARGS=$(echo $CLASSNAMES | awk '{for (i=1; i<=NF; i++) print "--tests",$i}')
            echo "Prepared arguments for Gradle: $GRADLE_ARGS"
            ./gradlew clean module-with-tests-to-run:test $GRADLE_ARGS

note: I tried to get the formatting right but I might have goofed.

Naruto Sempai
  • 6,233
  • 8
  • 35
  • 51