-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integration tests for htex vs code serialization caches
it would be nice to parameterise these rather than have two distinct copies the reason for testing with alternate mode too is because that has monitoring on, for exmaple, which does different wrapping and has caused cache failures in the past. most immediately i'm investigating this because inside desc I am seeing some cache failures that are unexpected...
- Loading branch information
1 parent
9bae880
commit 111860a
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
parsl/tests/test_serialization/test_htex_alternate_cache.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import parsl | ||
import pytest | ||
|
||
from typing import Any | ||
|
||
from parsl.serialize.facade import methods_for_code | ||
|
||
from parsl.tests.configs.htex_local_alternate import fresh_config as local_config | ||
|
||
|
||
@parsl.python_app | ||
def f(x): | ||
return x + 1 | ||
|
||
|
||
@pytest.mark.local | ||
def test_caching() -> None: | ||
# for future serializer devs: if this is failing because you added another | ||
# code serializer, you'll also probably need to re-think what is being tested | ||
# about serialization caching here. | ||
assert len(methods_for_code) == 1 | ||
|
||
serializer = methods_for_code[b'C2'] | ||
|
||
# force type to Any here because a serializer method coming from | ||
# methods_for_code doesn't statically have any cache management | ||
# methods on itself such as cache_clear or cache_info. | ||
serialize_method: Any = serializer.serialize | ||
|
||
serialize_method.cache_clear() | ||
|
||
assert serialize_method.cache_info().hits == 0 | ||
assert serialize_method.cache_info().misses == 0 | ||
assert serialize_method.cache_info().currsize == 0 | ||
|
||
assert f(7).result() == 8 | ||
|
||
# the code serializer cache should now contain only a (probably wrapped) f ... | ||
assert serialize_method.cache_info().currsize == 1 | ||
|
||
# ... which was not already in the cache. | ||
assert serialize_method.cache_info().misses == 1 | ||
assert serialize_method.cache_info().hits == 0 | ||
|
||
assert f(100).result() == 101 | ||
|
||
# this time round, we should have got a single cache hit... | ||
assert serialize_method.cache_info().hits == 1 | ||
assert serialize_method.cache_info().misses == 1 | ||
assert serialize_method.cache_info().currsize == 1 | ||
|
||
assert f(200).result() == 201 | ||
|
||
# this time round, we should have got another single cache hit... | ||
assert serialize_method.cache_info().hits == 2 | ||
assert serialize_method.cache_info().misses == 1 | ||
assert serialize_method.cache_info().currsize == 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import parsl | ||
import pytest | ||
|
||
from typing import Any | ||
|
||
from parsl.serialize.facade import methods_for_code | ||
|
||
from parsl.tests.configs.htex_local import fresh_config as local_config | ||
|
||
|
||
@parsl.python_app | ||
def f(x): | ||
return x + 1 | ||
|
||
|
||
@pytest.mark.local | ||
def test_caching() -> None: | ||
# for future serializer devs: if this is failing because you added another | ||
# code serializer, you'll also probably need to re-think what is being tested | ||
# about serialization caching here. | ||
assert len(methods_for_code) == 1 | ||
|
||
serializer = methods_for_code[b'C2'] | ||
|
||
# force type to Any here because a serializer method coming from | ||
# methods_for_code doesn't statically have any cache management | ||
# methods on itself such as cache_clear or cache_info. | ||
serialize_method: Any = serializer.serialize | ||
|
||
serialize_method.cache_clear() | ||
|
||
assert serialize_method.cache_info().hits == 0 | ||
assert serialize_method.cache_info().misses == 0 | ||
assert serialize_method.cache_info().currsize == 0 | ||
|
||
assert f(7).result() == 8 | ||
|
||
# the code serializer cache should now contain only a (probably wrapped) f ... | ||
assert serialize_method.cache_info().currsize == 1 | ||
|
||
# ... which was not already in the cache. | ||
assert serialize_method.cache_info().misses == 1 | ||
assert serialize_method.cache_info().hits == 0 | ||
|
||
assert f(100).result() == 101 | ||
|
||
# this time round, we should have got a single cache hit... | ||
assert serialize_method.cache_info().hits == 1 | ||
assert serialize_method.cache_info().misses == 1 | ||
assert serialize_method.cache_info().currsize == 1 | ||
|
||
assert f(200).result() == 201 | ||
|
||
# this time round, we should have got another single cache hit... | ||
assert serialize_method.cache_info().hits == 2 | ||
assert serialize_method.cache_info().misses == 1 | ||
assert serialize_method.cache_info().currsize == 1 |