File: test_no_recovery_no_connect_async.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (62 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------
import asyncio
import pytest
from devtools_testutils.aio import recorded_by_proxy_async
from testcase import WebpubsubClientPowerShellPreparer
from testcase_async import WebpubsubClientTestAsync, TEST_RESULT_ASYNC, on_group_message
from azure.messaging.webpubsubclient.models import (
    WebPubSubProtocolType,
    SendMessageError,
)


@pytest.mark.live_test_only
class TestWebpubsubClientNoRecoveryNoReconnectAsync(WebpubsubClientTestAsync):
    # disable recovery and auto reconnect
    @WebpubsubClientPowerShellPreparer()
    @recorded_by_proxy_async
    async def test_disable_recovery_and_autoconnect_async(self, webpubsubclient_connection_string):
        client = await self.create_client(
            connection_string=webpubsubclient_connection_string,
            reconnect_retry_total=0,
            protocol_type=WebPubSubProtocolType.JSON,
        )
        name = "test_disable_recovery_and_autoconnect_async"
        async with client:
            group_name = name
            await client.subscribe("group-message", on_group_message)
            await client.join_group(group_name)
            await client._ws.session.close()  # close connection
            with pytest.raises(SendMessageError):
                await client.send_to_group(group_name, name, "text")
            await asyncio.sleep(1)  # wait for on_group_message to be called

        assert name not in TEST_RESULT_ASYNC

    # disable recovery and auto reconnect, then send message concurrently
    @WebpubsubClientPowerShellPreparer()
    @recorded_by_proxy_async
    async def test_disable_recovery_and_autoconnect_send_concurrently_async(
        self, webpubsubclient_connection_string
    ):
        client = await self.create_client(
            connection_string=webpubsubclient_connection_string,
            reconnect_retry_total=0,
            message_retry_total=3,
            protocol_type=WebPubSubProtocolType.JSON,
        )

        async with client:
            group_name = "test_disable_recovery_and_autoconnect_send_concurrently_async"
            await client.join_group(group_name)
            count = 10
            tasks = [client.send_to_group(group_name, "hello", "text") for _ in range(10)]
            await client._ws.session.close()  # close connection
            for task in asyncio.as_completed(tasks):
                with pytest.raises(SendMessageError):
                    await task