Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow-up of #711 Make sure calling disconnect is safe when connection isn't established or half-established (i.e: protocol/transport exist but session is not ready). Test1 Call to disconnect is safe when there's no existing connection ``` > python -m IPython Python 3.10.0 (default, Oct 13 2021, 06:45:00) [Clang 13.0.0 (clang-1300.0.29.3)] In [1]: import sys; sys.path.insert(0, "~/Documents/github/opcua-asyncio"); import asyncua; c = asyncua.Client(url="opc.tcp://localhost:4840",timeout=10 ...: ); In [2]: await c.disconnect() close_session but connection wasn't established close_secure_channel was called but connection is closed In [3]: ``` Test2 Calling to disconnect is safe when there's no session established. To simulate this, I add delay to the server internal_session on session creation. I check that the client connects and disconnect from the server logs. Finally, the client doesn't raise any error. Ad delay to the internal server ``` > python -m IPython Python 3.10.0 (default, Oct 13 2021, 06:45:00) [Clang 13.0.0 (clang-1300.0.29.3)] In [1]: import sys; sys.path.insert(0, "~/Documents/github/opcua-asyncio"); import asyncua; c = asyncua.Client(url="opc.tcp://localhost:4840",timeout=10 ...: ); import threading; import asyncio; In [2]: In [2]: async def connect(c): ...: await c.connect() ...: In [3]: async def disco(c): ...: await c.disconnect() ...: In [4]: L = await asyncio.gather(connect(c), disco(c)) close_session but connection wasn't established close_secure_channel was called but connection is closed In [5]: quit; ```
- Loading branch information
This will not catch
asyncio.CancelledError
on Python 3.8+, since Python 3.8asyncio.CancelledError
is subclass ofBaseException
.