voxpupuli / rspec-puppet-facts

Simplify your unit tests by looping on every supported Operating System and populating facts.
Apache License 2.0
61 stars 53 forks source link

Use a single FacterDB.get_facts call #158

Open ekohl opened 11 months ago

ekohl commented 11 months ago

The major cost is FacterDB.get_facts. Instead of calling it once for every OS version this instead calls it once with a complex filter. It then uses JGrep to simulate another smaller DB and futher query that.

In my non-scientific test this reduces the load time of puppet-example from 3.5 to 2.5 seconds.

This is VERY hacky and duplicates logic from FacterDB which it really should not do. There is also overhead of serializing to JSON, loading that back and doing symbol conversion. It may be possible to use JGrep.filter_json, but that probably fails on the symbol keys. If FacterDB.get_facts could return string keys all of that would be redundant.

codecov[bot] commented 11 months ago

Codecov Report

Patch coverage: 100.00% and project coverage change: -1.06 :warning:

Comparison is base (5c92f4f) 95.20% compared to head (2314825) 94.15%.

:exclamation: Current head 2314825 differs from pull request most recent head f7a1e25. Consider uploading reports for the commit f7a1e25 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #158 +/- ## ========================================== - Coverage 95.20% 94.15% -1.06% ========================================== Files 2 2 Lines 167 171 +4 ========================================== + Hits 159 161 +2 - Misses 8 10 +2 ``` | [Impacted Files](https://app.codecov.io/gh/voxpupuli/rspec-puppet-facts/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=voxpupuli) | Coverage Δ | | |---|---|---| | [lib/rspec-puppet-facts.rb](https://app.codecov.io/gh/voxpupuli/rspec-puppet-facts/pull/158?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=voxpupuli#diff-bGliL3JzcGVjLXB1cHBldC1mYWN0cy5yYg==) | `96.98% <100.00%> (-1.17%)` | :arrow_down: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

ekohl commented 11 months ago

Updated to use https://github.com/voxpupuli/facterdb/pull/282.