Skip to content

ci: Split tests run in CI #12064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

ci: Split tests run in CI #12064

wants to merge 23 commits into from

Conversation

JagjeevanAK
Copy link
Contributor

What

Screenshot

Related issue(s) and discussion

  • Fixes #[ISSUE NUMBER]

Signed-off-by: Jagjeevan Kashid <[email protected]>
@JagjeevanAK JagjeevanAK requested a review from a team as a code owner June 21, 2025 06:57
@github-project-automation github-project-automation bot moved this to To discuss and validate in 🍊 Open Food Facts Server issues Jun 21, 2025
@JagjeevanAK JagjeevanAK changed the title CI: Testing gnu parllel for unit tests ci: Testing gnu parllel for unit tests Jun 21, 2025
@github-actions github-actions bot added the GitHub Actions Pull requests that update Github_actions code label Jun 21, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jun 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.20%. Comparing base (d766aa2) to head (8266725).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12064      +/-   ##
==========================================
- Coverage   50.46%   50.20%   -0.26%     
==========================================
  Files          90       90              
  Lines       23900    23900              
  Branches     5743     5743              
==========================================
- Hits        12062    12000      -62     
  Misses      10357    10357              
- Partials     1481     1543      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added the 🐋 Docker https://docker-curriculum.com/ label Jun 21, 2025
@github-actions github-actions bot added 🧪 tests dependencies Pull requests that update a dependency file labels Jun 21, 2025
Signed-off-by: Jagjeevan Kashid <[email protected]>
download_tmp_dir: ${{ runner.temp }}
- name: tests
image: "openfoodfacts-server/backend:dev"
# downloadbackendimage task loads the image into docker and keeps the original file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary for ishworkh/[email protected]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really ? I will see docs and will update it thanks for pointing it out.

# Unit test groups for parallel execution in CI
# Usage: make unit_test_group TEST_GROUP=1
# Groups are balanced by number of test files
define UNIT_TEST_GROUPS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the groups be determined algorithmically? All jobs of the actions matrix use the same source, so that the groups could be built automatically to avoid having to add each test file here in the Makefile individually

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made group on there size as small are combined with large one so that run it in equal time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the idea of having hard-coded groups. It will be too easy to add a test and forget to include it which means the test will run locally but not in CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point never though of this will look into it.

Copy link
Contributor Author

@JagjeevanAK JagjeevanAK Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @john-gom, @hangy what do you think instead of hard coding making directory inside of existing directory of tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JagjeevanAK I think it's better to create a script that you call and gives you back the test group, it should also take the number of group as parameter.

This script would list all tests, using file system) and separate into groups in a predictable manner (eg. after sorting the list), and print the list on stdout.

Then in makefile you can just call the script to get the test group.

The script might be written in python, as it's found on most machines today.

Please put the script in a sub folder, eg. scripts/tests/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, in bash this is as simple as eg.:

find tests/unit -name "*.t"|sort|split -n 1/10
find tests/unit -name "*.t"|sort|split -n 2/10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alex problem is that some test are taking time so I have mixed it with small and big.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some e2e test like some what 2-3 if I am not wrong.

@hangy hangy requested review from a team and Copilot June 21, 2025 14:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the CI setup by adding grouped, parallel execution for both unit and integration tests in the Makefile and the GitHub Actions workflow.

  • Introduce unit_test_group and integration_test_group targets in the Makefile to run test subsets in parallel.
  • Update .github/workflows/pull_request.yml to set up Docker Buildx, cache BuildKit, build the backend image, and use a matrix strategy for parallel test jobs.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
Makefile Add grouped parallel test targets (unit_test_group, integration_test_group) and supporting variables.
.github/workflows/pull_request.yml Configure Docker Buildx, caching layers, and matrix-based parallel unit/integration test jobs.
Comments suppressed due to low confidence (3)

.github/workflows/pull_request.yml:80

  • The hashFiles call includes single quotes around patterns, which can be interpreted literally. Remove the internal quotes so patterns are passed directly (e.g., hashFiles(Dockerfile*, docker-compose.yml, docker/**, cpanfile*, conf/apache*)).
          key: ${{ runner.os }}-docker-${{ hashFiles('Dockerfile*', 'docker-compose.yml', 'docker/**', 'cpanfile*', 'conf/apache*') }}

.github/workflows/pull_request.yml:21

  • [nitpick] The filter job is marked with a TODO and has no steps. If it’s not currently used, consider removing it to simplify the workflow.
  filter:

Makefile:611

  • [nitpick] The grouping logic spans many test files. Adding a brief explanation of the grouping strategy or moving the lists to a separate include file could improve readability and maintenance.
# Unit test groups for parallel execution in CI

JagjeevanAK and others added 6 commits June 21, 2025 20:21
my mistake while testing it remained

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Jagjeevan Kashid <[email protected]>
Signed-off-by: Jagjeevan Kashid <[email protected]>
fix increased no. of groups form 4 to6

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Jagjeevan Kashid <[email protected]>
Signed-off-by: Jagjeevan Kashid <[email protected]>
Copy link

@JagjeevanAK
Copy link
Contributor Author

hey @alexgarel,

This PR is ready to merge.

@john-gom
Copy link
Contributor

It would be good to see some kind of comparison with not using groups but just running the unit and integration tests as separate parallel tasks. That way we can see how much time the group approach is actually saving

@JagjeevanAK
Copy link
Contributor Author

group approach is good according to me because every time we need to spin the resource for each test and that might take time.

@alexgarel alexgarel changed the title ci: Testing gnu parllel for unit tests ci: Split tests run in CI Jun 23, 2025
# Unit test groups for parallel execution in CI
# Usage: make unit_test_group TEST_GROUP=1
# Groups are balanced by number of test files
define UNIT_TEST_GROUPS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JagjeevanAK I think it's better to create a script that you call and gives you back the test group, it should also take the number of group as parameter.

This script would list all tests, using file system) and separate into groups in a predictable manner (eg. after sorting the list), and print the list on stdout.

Then in makefile you can just call the script to get the test group.

The script might be written in python, as it's found on most machines today.

Please put the script in a sub folder, eg. scripts/tests/

mkdir -p tests/unit/outputs/
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb
@echo "🥫 Running all tests in group $(TEST_GROUP) with parallel execution and JUnit XML generation..."
${DOCKER_COMPOSE_TEST} run ${COVER_OPTS} -e JUNIT_TEST_FILE="tests/unit/outputs/junit_group_$(TEST_GROUP).xml" -T --rm backend yath test --renderer=Formatter --renderer=JUnit --job-count=${CPU_COUNT} $(addprefix tests/unit/,$(call get_unit_group_tests,$(TEST_GROUP)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we loose coverage with this new run type ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to me it should not and this is ordered this way because each test was running double previously.

# Unit test groups for parallel execution in CI
# Usage: make unit_test_group TEST_GROUP=1
# Groups are balanced by number of test files
define UNIT_TEST_GROUPS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, in bash this is as simple as eg.:

find tests/unit -name "*.t"|sort|split -n 1/10
find tests/unit -name "*.t"|sort|split -n 2/10

@@ -289,10 +289,12 @@ unit_test: create_folders
@echo "🥫 Running unit tests …"
mkdir -p tests/unit/outputs/
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb
@echo "🥫 Running tests with yath (parallel jobs: ${CPU_COUNT})"
${DOCKER_COMPOSE_TEST} run ${COVER_OPTS} -e JUNIT_TEST_FILE="tests/unit/outputs/junit.xml" -T --rm backend yath test --renderer=Formatter --renderer=JUnit --job-count=${CPU_COUNT} tests/unit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here unit tests might run in parallel directly thanks to yath, without having to run them in different github runner. Is it that CPU_COUNT is too low in each runner ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check

@github-actions github-actions bot added the 💥 Merge Conflicts 💥 Merge Conflicts label Jul 2, 2025
@teolemon teolemon moved this from To discuss and validate to PRs in 🍊 Open Food Facts Server issues Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file 🐋 Docker https://docker-curriculum.com/ GitHub Actions Pull requests that update Github_actions code 💥 Merge Conflicts 💥 Merge Conflicts 🧪 tests
Projects
Development

Successfully merging this pull request may close these issues.

5 participants