@@ -620,20 +620,25 @@ def test_sequential_control_messages():
620620 # Get replies
621621 replies = [get_reply (kc , msg_id , channel = "control" ) for msg_id in msg_ids ]
622622
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+
623634 # Check messages are processed in order, one at a time, and of a sensible duration.
624635 previous_end = None
625636 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" ])
634639
635640 if previous_end is not None :
636- assert start > previous_end
641+ assert start >= previous_end
637642 previous_end = end
638643
639644 assert end >= start + timedelta (seconds = sleep )
0 commit comments