@@ -594,3 +594,44 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
594594 # The key test is that the code runs without errors and includes partition key in calculation
595595 assert throttle_sizes [0 ] >= 1 , "Should include partition key in size calculation"
596596 assert throttle_sizes [1 ] >= 1 , "Should calculate size for item without partition key"
597+
598+ @pytest .mark .asyncio
599+ async def test_just_created_survives_reconnection (self , random_stream_name , endpoint_url ):
600+ """Test that _just_created state persists across reconnection attempts (Issue #56).
601+
602+ When create_stream=True and the backend is slow to make the stream visible,
603+ start() sets self.create_stream = False after _create_stream(). If the 60s
604+ describe timeout expires and get_conn() triggers a reconnection, the second
605+ start() call must still know the stream was just created so it retries
606+ StreamDoesNotExist instead of propagating immediately.
607+ """
608+ producer = Producer (
609+ stream_name = random_stream_name ,
610+ endpoint_url = endpoint_url ,
611+ region_name = "ap-southeast-2" ,
612+ create_stream = True ,
613+ create_stream_shards = 1 ,
614+ )
615+
616+ assert producer ._just_created is False
617+ assert producer .create_stream is True
618+
619+ # Simulate what start() does: create stream, flip flags
620+ await producer .get_client ()
621+ await producer ._create_stream ()
622+ producer .create_stream = False
623+ producer ._just_created = True
624+
625+ # After first start() sets create_stream=False, a reconnection calls start() again.
626+ # _just_created must still be True so the retry logic handles StreamDoesNotExist.
627+ assert producer .create_stream is False
628+ assert producer ._just_created is True
629+
630+ # Now simulate a successful second start() — stream becomes ACTIVE
631+ await producer .start ()
632+
633+ # After stream confirmed ACTIVE, _just_created should be reset
634+ assert producer ._just_created is False
635+ assert producer .stream_status == producer .ACTIVE
636+
637+ await producer .close ()
0 commit comments