File tree 4 files changed +25
-3
lines changed
4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,9 @@ class MessageBus(BaseMessageBus):
110
110
:ivar unique_name: The unique name of the message bus connection. It will
111
111
be :class:`None` until the message bus connects.
112
112
:vartype unique_name: str
113
+ :ivar connected: True if this message bus is expected to be able to send
114
+ and receive messages.
115
+ :vartype connected: bool
113
116
"""
114
117
def __init__ (self ,
115
118
bus_address : str = None ,
Original file line number Diff line number Diff line change @@ -139,6 +139,9 @@ class MessageBus(BaseMessageBus):
139
139
:class:`AuthExternal <dbus_next.auth.AuthExternal>`.
140
140
:type auth: :class:`Authenticator <dbus_next.auth.Authenticator>`
141
141
142
+ :ivar connected: True if this message bus is expected to be able to send
143
+ and receive messages.
144
+ :vartype connected: bool
142
145
:ivar unique_name: The unique name of the message bus connection. It will
143
146
be :class:`None` until the message bus connects.
144
147
:vartype unique_name: str
Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ class BaseMessageBus:
44
44
:ivar unique_name: The unique name of the message bus connection. It will
45
45
be :class:`None` until the message bus connects.
46
46
:vartype unique_name: str
47
+ :ivar connected: True if this message bus is expected to be able to send
48
+ and receive messages.
49
+ :vartype connected: bool
47
50
"""
48
51
def __init__ (self ,
49
52
bus_address : Optional [str ] = None ,
@@ -82,6 +85,12 @@ def __init__(self,
82
85
83
86
self ._setup_socket ()
84
87
88
+ @property
89
+ def connected (self ):
90
+ if self .unique_name is None or self ._disconnected or self ._user_disconnect :
91
+ return False
92
+ return True
93
+
85
94
def export (self , path : str , interface : ServiceInterface ):
86
95
"""Export the service interface on this message bus to make it available
87
96
to other clients.
Original file line number Diff line number Diff line change 10
10
async def test_bus_disconnect_before_reply (event_loop ):
11
11
'''In this test, the bus disconnects before the reply comes in. Make sure
12
12
the caller receives a reply with the error instead of hanging.'''
13
-
14
- bus = await MessageBus ().connect ()
13
+ bus = MessageBus ()
14
+ assert not bus .connected
15
+ await bus .connect ()
16
+ assert bus .connected
15
17
16
18
ping = bus .call (
17
19
Message (destination = 'org.freedesktop.DBus' ,
@@ -25,12 +27,16 @@ async def test_bus_disconnect_before_reply(event_loop):
25
27
await ping
26
28
27
29
assert bus ._disconnected
30
+ assert not bus .connected
28
31
assert (await bus .wait_for_disconnect ()) is None
29
32
30
33
31
34
@pytest .mark .asyncio
32
35
async def test_unexpected_disconnect (event_loop ):
33
- bus = await MessageBus ().connect ()
36
+ bus = MessageBus ()
37
+ assert not bus .connected
38
+ await bus .connect ()
39
+ assert bus .connected
34
40
35
41
ping = bus .call (
36
42
Message (destination = 'org.freedesktop.DBus' ,
@@ -44,6 +50,7 @@ async def test_unexpected_disconnect(event_loop):
44
50
await ping
45
51
46
52
assert bus ._disconnected
53
+ assert not bus .connected
47
54
48
55
with pytest .raises (OSError ):
49
56
await bus .wait_for_disconnect ()
You can’t perform that action at this time.
0 commit comments