Repository navigation
test: fix the two remaining Windows unit-test failures (#1460) - #1477
Open
PRINCE2-AI wants to merge 1 commit into
Open
PRINCE2-AI wants to merge 1 commit into
PRINCE2-AI wants to merge 1 commit into
Conversation
The cache-expiry test set the TTL to 0, but Windows time.monotonic() has 15.6 ms resolution, so two calls can land in one tick and the entry still looks fresh. Move the module clock past the TTL instead. The tracker test patched codecarbon.core.gpu.pynvml, which nothing reads: AllGPUDevices and NvidiaGPUDevice go through codecarbon.core.gpu_nvidia.pynvml, so a real driver was queried whenever one was installed.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the two Windows failures left in #1460. Both changes are test-only.
1.
test_expired_cache_entry_is_refetched(Windows, Python 3.12 and older)The test patched
ELECTRICITYMAPS_CACHE_TTLto0and expected the second call to refetch. The cache check istime.monotonic() - cached[0] <= ELECTRICITYMAPS_CACHE_TTL, and on Windows Python 3.12time.monotonic()usesGetTickCount64()(15.6 ms resolution): two calls inside one tick give a difference of exactly0, the entry still looks fresh, and the test observes one request instead of two.The test now moves the module's clock past the TTL instead of shrinking the TTL, so it checks the same "entry older than TTL" contract without depending on clock resolution. The patch replaces the name
timeinelectricitymaps_api's namespace, which leaves the real clock in place forrequestsandresponses.2.
test_task_energy_with_live_update_interference(any machine with an NVIDIA driver)TestCarbonTrackerpatchedcodecarbon.core.gpu.pynvml, butAllGPUDevicesandNvidiaGPUDevicereadcodecarbon.core.gpu_nvidia.pynvml(codecarbon/core/gpu.py:35-38,codecarbon/core/gpu_nvidia.py:54).gpu.pynvmlis only a backwards-compatible alias, so on a machine with a driver the test queried real GPU energy and overshot the expected total. The patch now targets the module that is actually read.Group 1 of #1460 no longer applies: #1462 skips the RAPL tests off Linux.
Fixes #1460.
Verification
masterab8627a1,-m "not integ_test",tests/test_viz_data.pyexcluded becausedashis not installed:871 passed, 1 failed— the failure wastest_expired_cache_entry_is_refetched. It also fails on Python 3.11 here.tests/test_electricitymaps_cache.py tests/test_emissions_tracker.py→51 passed.ruff format --checkclean on both files.ruff checkreports the same 5 pre-existing findings asmaster, none on a changed line.I could not reproduce the GPU test locally: this machine has no NVIDIA GPU, so
test_task_energy_with_live_update_interferencepasses either way here. That half follows hifarrer's reproduction in #1460, where patchingcodecarbon.core.gpu_nvidia.pynvmlmade it pass on a driver-equipped machine.Types of changes
AI Usage Disclosure
Checklist