-
Notifications
You must be signed in to change notification settings - Fork 75
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
test: add helper method for overriding env variables #3022
test: add helper method for overriding env variables #3022
Conversation
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, final comment is around method naming to make things obvious and avoid wasted troubleshooting time form this improvement
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, but now there is a merge conflict.
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> # Conflicts: # packages/relay/src/lib/services/ethService/ethFilterService/index.ts # packages/relay/tests/lib/clients/localLRUCache.spec.ts # packages/relay/tests/lib/eth/eth_call.spec.ts # packages/relay/tests/lib/eth/eth_estimateGas.spec.ts # packages/relay/tests/lib/eth/eth_feeHistory.spec.ts # packages/relay/tests/lib/eth/eth_gasPrice.spec.ts # packages/relay/tests/lib/eth/eth_getBalance.spec.ts # packages/relay/tests/lib/eth/eth_getBlockByHash.spec.ts # packages/relay/tests/lib/eth/eth_getBlockByNumber.spec.ts # packages/relay/tests/lib/eth/eth_getCode.spec.ts # packages/relay/tests/lib/eth/eth_getLogs.spec.ts # packages/relay/tests/lib/eth/eth_getStorageAt.spec.ts # packages/relay/tests/lib/eth/eth_getTransactionCount.spec.ts # packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts # packages/relay/tests/lib/hapiService.spec.ts # packages/relay/tests/lib/hbarLimiter.spec.ts # packages/relay/tests/lib/mirrorNodeClient.spec.ts # packages/relay/tests/lib/precheck.spec.ts # packages/relay/tests/lib/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.spec.ts # packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts # packages/relay/tests/lib/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.spec.ts # packages/relay/tests/lib/sdkClient.spec.ts # packages/relay/tests/lib/services/cacheService/cacheService.spec.ts # packages/relay/tests/lib/services/debugService/debug.spec.ts # packages/relay/tests/lib/services/eth/filter.spec.ts # packages/relay/tests/lib/services/metricService/metricService.spec.ts # packages/relay/tests/lib/web3.spec.ts # packages/server/tests/acceptance/cacheService.spec.ts # packages/server/tests/acceptance/hbarLimiter.spec.ts # packages/server/tests/acceptance/rpc_batch3.spec.ts # packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts # packages/ws-server/tests/unit/utils.spec.ts # packages/ws-server/tests/unit/validations.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> # Conflicts: # packages/relay/tests/lib/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.spec.ts # packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> # Conflicts: # packages/relay/tests/lib/repositories/hbarLimiter/ethAddressHbarSpendingPlanRepository.spec.ts # packages/relay/tests/lib/repositories/hbarLimiter/hbarSpendingPlanRepository.spec.ts
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Quality Gate failedFailed conditions |
🚨 Memory Leak Detected 🚨A potential memory leak has been detected in the test titled Details📊 Memory Leak Detection Report 📊 GC Type: MarkSweepCompact Heap Statistics (before vs after executing the test):
Heap Space Statistics (before vs after executing the test):
RecommendationsPlease investigate the memory allocations in this test, focusing on objects that are not being properly deallocated. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3022 +/- ##
==========================================
- Coverage 84.88% 82.54% -2.34%
==========================================
Files 43 61 +18
Lines 3216 4063 +847
Branches 649 806 +157
==========================================
+ Hits 2730 3354 +624
- Misses 283 471 +188
- Partials 203 238 +35
Flags with carried forward coverage won't be shown. Click here to find out more.
|
* test: add helper method for overriding env variables Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: improve readability Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: usages Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: cacheService.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: utils.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: relay.spec.ts and sdkClient.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: eth_call.spec.ts, eth_estimateGas.spec.ts, ethGetBlockBy.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: use helper method to override envs in acceptance test specs Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: hapiService.spec.ts and precheck.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: sdkClient.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: cacheService.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: metricService.spec.ts and subscriptionController.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: rateLimiter.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: failing tests Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: revert some changes in rpc_batch3.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: subscribe.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: add docs with examples to `overrideEnvs` and `withOverriddenEnvs` Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: address comments Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: build image test Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * Merge branch 'main' into add-helper-method-for-overriding-env-variables Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: address comments + fix conflicts after merge Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: optimize TTL tests in localLRUCache.spec.ts Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * fix: failing unit test after merge from main Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> * chore: optimize imports after merge from main Signed-off-by: Victor Yanev <victor.yanev@limechain.tech> --------- Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
Description:
In the current setup, there is no straightforward way to temporarily override environment variables for the duration of a test suite. This can lead to issues where tests inadvertently affect each other due to shared environment settings, making it difficult to isolate and reproduce test failures.
Additionally, in many tests environment variables are overridden without being reverted, propagating this behavior to other tests and making the tests dependent on their order and leading to chain-failures in cases where only one of the tests actually fails.
Changes:
This PR adds new helper methods
overrideEnvs
andwithOverriddenEnvs
which provide a mechanism to temporarily set environment variables for the duration of a test or a group of tests.ℹ️ These methods ensure that the original environment settings are restored after the tests have run, maintaining the integrity of the global environment.
overrideEnvs
: Temporarily sets environment variables before a test and restores them afterward.withOverriddenEnvs
: A higher-level function that usesoverrideEnvs
to set environment variables for a group of tests defined within a callback function.Related issue(s):
Fixes #3029
Checklist