Skip to content
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

Optimize tests that run fix_rules.py #10968

Merged
merged 3 commits into from
Aug 10, 2023

Conversation

jan-cerny
Copy link
Collaborator

Description:

We currently have multiple CTest tests that run fix_rules.py, eg. fix_rules-empty_identifiers, fix_rules-invalid_identifiers, fix_rules-duplicate_subkeys. There is 8 of them and each runs for ~ 10 seconds.

Each of the tests runs a different subcommand of fix_rules.py. These tests test various aspects of rule.yml files. Each test
tests all rule.yml files in a product. That means that each test loads all rule.yml files to perform the check. This isn't
efficient and takes a lot of time.

We will introduce a new subcommand test_all to fix_rules.py . This subcommand can run all checks at once. It iterates over rules and on each rule it runs multiple checks. Each rule.yml is loaded and parsed just once.

Therefore, we will merge all the CTest tests that run fix_rules.py to a single test. This way, we will parse each rule.yml file single time instead of 8 times during the test run, and that will save us a lot of time during testing.

Rationale:

GitHub Actions CI speed up.

Review Hints:

Modify some rules so that the test is trigerred, for example, break ordering of items in prodtype key or break soorting of references in rule.yml. Then run ctest --verbose -R fix_rules in build directory.

Change callback functions which name starts with `has_` so that these
functions won't load YAML files inside them but instead they will
consume a loaded YAML as a parameter.  This will separate the logic from
YAML parsing allow us to reuse these functions in a different context in
future. The functions are used as a callback therefore they all need to
have the same interface but that can lead to unused parameters in some
of the functions.
This commit adds a new subcommand `test_all` to the `fix_rules.py`
script.  The subcommand will execute all checks that are present in this
script on all rules in the product.  In other words, it works like
executing all currently existing subcommands in `--dry-run` mode at once.
We currently call the subcomands of this script in `--dry-run` mode
in our CTest test. This change will allow us to merge these tests
in a single test case.
We currently have multiple CTest tests that run `fix_rules.py`.
Each of the tests runs a different subcommand of `fix_rules.py`.
These tests test various aspects of rule.yml files. Each test
tests all rule.yml files in a product. That means that each
test loads all rule.yml files to perform the check. This isn't
efficient and takes a lot of time. Thanks to the new subcommand
`test_all` that has been introduced to `fix_rules.py` recently,
we can run all checks at once. Therefore, we will merge all
the CTest tests that run `fix_rules.py` to a single test.
This way, we will parse each rule.yml file just once, and that
will save us a lot of time during testing.
@jan-cerny jan-cerny added the Test Suite Update in Test Suite. label Aug 9, 2023
@jan-cerny jan-cerny added this to the 0.1.70 milestone Aug 9, 2023
@github-actions
Copy link

github-actions bot commented Aug 9, 2023

Start a new ephemeral environment with changes proposed in this pull request:

Fedora Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@Mab879 Mab879 self-assigned this Aug 9, 2023
@codeclimate
Copy link

codeclimate bot commented Aug 9, 2023

Code Climate has analyzed commit a429d02 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 4

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 53.3% (0.0% change).

View more on Code Climate.

Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I can confirm that the tests still work and the number of tests is reduced.

@Mab879
Copy link
Member

Mab879 commented Aug 10, 2023

I'm waving the code climate finings as this was how the code was before. We look to refactor this later.

@Mab879 Mab879 merged commit e5da0b0 into ComplianceAsCode:master Aug 10, 2023
29 of 30 checks passed
@jan-cerny jan-cerny deleted the test_fix_rules branch August 10, 2023 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Test Suite Update in Test Suite.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants