Skip to content

Commit 72cd86f

Browse files
authored
Mitigate test flakyness (#207)
Signed-off-by: Michel Hidalgo <mhidalgo@theaiinstitute.com>
1 parent eaf980b commit 72cd86f

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

synchros2/synchros2/logging.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ def log(message: str) -> bool:
9393
return log
9494

9595

96+
def clear_logging_caches() -> None:
97+
"""Clears the caches of memoized logging functions.
98+
99+
This is useful for testing purposes, to avoid interference between tests due to cached logging functions.
100+
"""
101+
make_logging_function.cache_clear()
102+
103+
96104
class MemoizingRcutilsLogger:
97105
"""An alternative, more efficient implementation of RcutilsLogger.
98106

synchros2/test/test_logging.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rclpy.time import Time
1010

1111
from synchros2.futures import unwrap_future
12-
from synchros2.logging import LoggingSeverity, logs_to_ros
12+
from synchros2.logging import LoggingSeverity, clear_logging_caches, logs_to_ros
1313
from synchros2.scope import ROSAwareScope
1414
from synchros2.subscription import Subscription
1515

@@ -29,6 +29,7 @@ def callback(message: Log) -> None:
2929

3030
logger = verbose_ros.node.get_logger()
3131
logger.set_level(LoggingSeverity.INFO)
32+
clear_logging_caches() # ensure no interference from previous tests
3233

3334
assert not logger.debug("Debug message should not be logged")
3435

synchros2/test/test_tf_listener_wrapper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def test_existing_transform(ros: ROSAwareScope, tf_pair: Tuple[MockTfPublisherNo
8686
timestamp = ros.node.get_clock().now()
8787
trans = Transform(translation=Vector3(x=1.0, y=2.0, z=3.0), rotation=Quaternion(w=1.0, x=0.0, y=0.0, z=0.0))
8888
tf_publisher.publish_transform(trans, timestamp)
89-
time.sleep(0.2)
90-
t = tf_listener.lookup_a_tform_b(FRAME_ID, CHILD_FRAME_ID, timestamp)
89+
t = tf_listener.lookup_a_tform_b(FRAME_ID, CHILD_FRAME_ID, timestamp, timeout_sec=10.0, wait_for_frames=True)
9190
assert equal_transform(t.transform, trans)
9291

9392

0 commit comments

Comments
 (0)