@@ -519,6 +519,56 @@ async def test_update_nonexistent_consumer_fails(jetstream: JetStream):
519519 await jetstream .update_consumer (stream_name = "test_stream" , consumer_name = "nonexistent" , max_deliver = 20 )
520520
521521
522+ @pytest .mark .asyncio
523+ async def test_create_or_update_consumer_creates_new (jetstream : JetStream ):
524+ """Test that create_or_update_consumer creates a new consumer when it doesn't exist."""
525+ # Create a stream
526+ await jetstream .create_stream (name = "test_stream" , subjects = ["FOO.*" ])
527+
528+ # Create a consumer using create_or_update
529+ consumer = await jetstream .create_or_update_consumer (
530+ stream_name = "test_stream" , name = "test_consumer" , durable_name = "test_consumer" , max_deliver = 10
531+ )
532+
533+ assert consumer .info .config .name == "test_consumer"
534+ assert consumer .info .config .max_deliver == 10
535+
536+
537+ @pytest .mark .asyncio
538+ async def test_create_or_update_consumer_updates_existing (jetstream : JetStream ):
539+ """Test that create_or_update_consumer updates an existing consumer."""
540+ # Create a stream and consumer
541+ await jetstream .create_stream (name = "test_stream" , subjects = ["FOO.*" ])
542+ await jetstream .create_consumer (
543+ stream_name = "test_stream" , name = "test_consumer" , durable_name = "test_consumer" , max_deliver = 10
544+ )
545+
546+ # Update the consumer using create_or_update
547+ updated_consumer = await jetstream .create_or_update_consumer (
548+ stream_name = "test_stream" , name = "test_consumer" , durable_name = "test_consumer" , max_deliver = 20
549+ )
550+
551+ assert updated_consumer .info .config .max_deliver == 20
552+
553+
554+ @pytest .mark .asyncio
555+ async def test_create_or_update_consumer_via_stream (jetstream : JetStream ):
556+ """Test create_or_update_consumer via Stream object."""
557+ # Create a stream
558+ stream = await jetstream .create_stream (name = "test_stream" , subjects = ["FOO.*" ])
559+
560+ # Create a consumer using create_or_update
561+ consumer = await stream .create_or_update_consumer (name = "test_consumer" , max_deliver = 10 )
562+
563+ assert consumer .info .config .name == "test_consumer"
564+ assert consumer .info .config .max_deliver == 10
565+
566+ # Update the same consumer
567+ updated_consumer = await stream .create_or_update_consumer (name = "test_consumer" , max_deliver = 20 )
568+
569+ assert updated_consumer .info .config .max_deliver == 20
570+
571+
522572@pytest .mark .asyncio
523573async def test_delete_nonexistent_consumer_fails (jetstream : JetStream ):
524574 """Test that deleting a non-existent consumer fails."""
0 commit comments