webcompere / system-stubs

System Stubs - Test Doubles for Java System resources
MIT License
92 stars 12 forks source link

Fix multi-threaded environment variable mocking #46

Closed ashleyfrieze closed 1 year ago

ashleyfrieze commented 2 years ago

Owing to a limitation of Mockito's mockStatic function, which deliberately limits static mocking to the calling thread, the environment variable mocking has not worked in any other worker threads involved in the test.

This was reported in #45

By switching from using Mockito to using ByteBuddy and mocking the ProcessEnvironment closer to the bytecode, we can overcome this constraint.

codecov-commenter commented 2 years ago

Codecov Report

Patch coverage: 28.57% and project coverage change: -3.56% :warning:

Comparison is base (3b4ea68) 84.76% compared to head (7c81ec9) 81.20%.

:exclamation: Current head 7c81ec9 differs from pull request most recent head 3af3bb4. Consider uploading reports for the commit 3af3bb4 to get more accurate results

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #46 +/- ## ============================================ - Coverage 84.76% 81.20% -3.56% + Complexity 347 326 -21 ============================================ Files 46 47 +1 Lines 755 761 +6 Branches 40 40 ============================================ - Hits 640 618 -22 - Misses 99 129 +30 + Partials 16 14 -2 ``` | [Files Changed](https://app.codecov.io/gh/webcompere/system-stubs/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webcompere) | Coverage Δ | | |---|---|---| | [...re/systemstubs/security/NoExitSecurityManager.java](https://app.codecov.io/gh/webcompere/system-stubs/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webcompere#diff-c3lzdGVtLXN0dWJzLWNvcmUvc3JjL21haW4vamF2YS91ay9vcmcvd2ViY29tcGVyZS9zeXN0ZW1zdHVicy9zZWN1cml0eS9Ob0V4aXRTZWN1cml0eU1hbmFnZXIuamF2YQ==) | `94.94% <ø> (-0.55%)` | :arrow_down: | | [...ere/systemstubs/stream/input/ThrowAtEndStream.java](https://app.codecov.io/gh/webcompere/system-stubs/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webcompere#diff-c3lzdGVtLXN0dWJzLWNvcmUvc3JjL21haW4vamF2YS91ay9vcmcvd2ViY29tcGVyZS9zeXN0ZW1zdHVicy9zdHJlYW0vaW5wdXQvVGhyb3dBdEVuZFN0cmVhbS5qYXZh) | `81.57% <ø> (ø)` | | | [...mstubs/internal/ProcessEnvironmentInterceptor.java](https://app.codecov.io/gh/webcompere/system-stubs/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webcompere#diff-c3lzdGVtLXN0dWJzLWludGVyY2VwdG9yL3NyYy9tYWluL2phdmEvdWsvb3JnL3dlYmNvbXBlcmUvc3lzdGVtc3R1YnMvaW50ZXJuYWwvUHJvY2Vzc0Vudmlyb25tZW50SW50ZXJjZXB0b3IuamF2YQ==) | `0.00% <0.00%> (ø)` | | | [...emstubs/environment/EnvironmentVariableMocker.java](https://app.codecov.io/gh/webcompere/system-stubs/pull/46?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=webcompere#diff-c3lzdGVtLXN0dWJzLWNvcmUvc3JjL21haW4vamF2YS91ay9vcmcvd2ViY29tcGVyZS9zeXN0ZW1zdHVicy9lbnZpcm9ubWVudC9FbnZpcm9ubWVudFZhcmlhYmxlTW9ja2VyLmphdmE=) | `93.02% <100.00%> (+40.39%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.