@@ -620,20 +620,25 @@ def test_sequential_control_messages():
620
620
# Get replies
621
621
replies = [get_reply (kc , msg_id , channel = "control" ) for msg_id in msg_ids ]
622
622
623
+ def ensure_datetime (arg ):
624
+ # Support arg which is a datetime or str.
625
+ if isinstance (arg , str ):
626
+ if sys .version_info [:2 ] < (3 , 11 ) and arg .endswith ("Z" ):
627
+ # Python < 3.11 doesn't support "Z" suffix in datetime.fromisoformat,
628
+ # so use alternative timezone format.
629
+ # https://github.com/python/cpython/issues/80010
630
+ arg = arg [:- 1 ] + "+00:00"
631
+ return datetime .fromisoformat (arg )
632
+ return arg
633
+
623
634
# Check messages are processed in order, one at a time, and of a sensible duration.
624
635
previous_end = None
625
636
for reply , sleep in zip (replies , sleeps ):
626
- start_str = reply ["metadata" ]["started" ]
627
- if sys .version_info [:2 ] < (3 , 11 ) and start_str .endswith ("Z" ):
628
- # Python < 3.11 doesn't support "Z" suffix in datetime.fromisoformat,
629
- # so use alternative timezone format.
630
- # https://github.com/python/cpython/issues/80010
631
- start_str = start_str [:- 1 ] + "+00:00"
632
- start = datetime .fromisoformat (start_str )
633
- end = reply ["header" ]["date" ] # Already a datetime
637
+ start = ensure_datetime (reply ["metadata" ]["started" ])
638
+ end = ensure_datetime (reply ["header" ]["date" ])
634
639
635
640
if previous_end is not None :
636
- assert start > previous_end
641
+ assert start >= previous_end
637
642
previous_end = end
638
643
639
644
assert end >= start + timedelta (seconds = sleep )
0 commit comments