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

Add Infection #29

Merged
merged 25 commits into from
Apr 30, 2023
Merged

Add Infection #29

merged 25 commits into from
Apr 30, 2023

Conversation

antonio-gg-dev
Copy link
Member

@antonio-gg-dev antonio-gg-dev commented Apr 28, 2023

📚 Description

Out of curiosity, I have installed and configured Infection in the project. It is a library that allows applying the mutation testing methodology in PHP. This methodology makes small modifications to the production code to try to detect whether the test suite detects these changes or not. Each of these small changes should always be detected by one of our tests. If not, the library reports it so that we can act accordingly.

This library thus makes our tests better, helping us achieve 100% coverage and ensuring that we test all edge cases. However, like everything else, being an automated process, it can also produce false positives. Therefore, it is up to our discretion to decide whether to fix or ignore these failures.

I launched the command to take a look and the truth is that we got a pretty good results. However, it still detected that one mutation had no coverage, 14 were not detected by any test, and 8 timed out. Nonetheless, we have some enviable metrics!

imagen
imagen

I'm creating this draft to work on it, so you can take a look and decide whether to incorporate this methodology (perhaps to apply it to the other Gacela modules) and to check the errors it has detected. We can also add it as a step in the CI pipeline.

🔖 Changes

  • I have installed Infection as a development dependency.
  • I have added Infection as new script in the composer.json file, in such a way that it launches as many threads as cores has the computer where the command is executed.
  • I have added this new script as the last step in the composer ctal script.
  • I have added a basic configuration for Infection to work for now, and we will have to fine-tune it gradually.

🤔 Considerations

Since my computer has 16 cores, the script's execution time is exactly 10 seconds, which is the default timeout amount. Currently, we have 8 timeouts, so on computers with less than 8 cores, the execution time will be between 20 and 80 seconds.

We need to study whether these timeouts are something we can fix (or ignore), so that we ensure they don't potentially add 10 seconds each on slower computers (those with a single core). However, since our test suite is so fast, another option we have is to drastically reduce the timeout amount. Nevertheless, as I mentioned earlier, we need to consider what to do in this situation.

@Chemaclass
Copy link
Member

I love the idea of incorporating mutation testing in this project. I want tests to test my tests! 💡🥳

@antonio-gg-dev antonio-gg-dev marked this pull request as ready for review April 30, 2023 10:20
@antonio-gg-dev
Copy link
Member Author

You might want to take a look at this: https://infection.github.io/guide/mutation-badge.html

@Chemaclass
Copy link
Member

Chemaclass commented Apr 30, 2023

I am using macos, and the $(nproc) that you are using in the composer script is unknown.
Could we find another command? Or maybe using a raw-int, @Tito-Kati ?
Screenshot 2023-04-30 at 13 06 44

Using --threads=4 takes: 17sec
Using --threads=8 takes: 8sec

I would suggest to use 8 threads 😄

@Chemaclass Chemaclass merged commit a9f24b6 into main Apr 30, 2023
@Chemaclass Chemaclass deleted the infection branch April 30, 2023 11:23
run: composer install --no-interaction --no-ansi --no-progress

- name: Run mutation tests
run: ./vendor/bin/infection --show-mutations --threads=$(nproc) --min-msi=100 --min-covered-msi=100

Choose a reason for hiding this comment

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

You can use --threads=max that will automatically get the number of cores on any OS

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you very much @maks-rafalko! The truth is that we discovered it yesterday while we were adding it to Gacela too.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, @maks-rafalko. I already changed it here 84df2cc

@Chemaclass Chemaclass added pure testing Pure testing related refactoring Refactoring or cleaning related labels May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pure testing Pure testing related refactoring Refactoring or cleaning related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants