Skip to content

Commit 42edf14

Browse files
pllimastrofrog
authored andcommitted
Merge pull request #11447 from embray/issue-11407
Fix for #11407
1 parent c102d21 commit 42edf14

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎astropy/samp/tests/test_web_profile.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import tempfile
1111
from urllib.request import Request, urlopen
1212

13-
import pytest
14-
1513
from astropy.utils.data import get_readable_fileobj
1614

1715
from astropy.samp import SAMPIntegratedClient, SAMPHubServer
@@ -23,14 +21,11 @@
2321

2422
from .test_standard_profile import TestStandardProfile as BaseTestStandardProfile
2523

26-
CI = os.environ.get('CI', False) == "true"
27-
2824

2925
def setup_module(module):
3026
conf.use_internet = False
3127

3228

33-
@pytest.mark.skipif(CI, reason="Flaky on CI")
3429
class TestWebProfile(BaseTestStandardProfile):
3530

3631
def setup_method(self, method):

‎astropy/samp/tests/web_profile_test_helpers.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,22 @@ def __init__(self, hub, name=None, description=None, metadata=None,
152152

153153
self.hub = hub
154154

155+
self._registration_lock = threading.Lock()
156+
self._registered_event = threading.Event()
155157
if self._callable:
156158
self._thread = threading.Thread(target=self._serve_forever)
157159
self._thread.daemon = True
158160

159161
def _serve_forever(self):
160162
while self.is_running:
163+
# Wait until we are actually registered before trying to do
164+
# anything, to avoid busy looping
161165
# Watch for callbacks here
162-
if self._is_registered:
166+
self._registered_event.wait()
167+
with self._registration_lock:
168+
if not self._is_registered:
169+
return
170+
163171
results = self.hub.pull_callbacks(self.get_private_key(), 0)
164172
for result in results:
165173
if result['samp.methodName'] == 'receiveNotification':
@@ -205,11 +213,20 @@ def register(self):
205213
self.declare_metadata()
206214

207215
self._is_registered = True
216+
# Let the client thread proceed
217+
self._registered_event.set()
208218

209219
else:
210220
raise SAMPClientError("Unable to register to the SAMP Hub. Hub "
211221
"proxy not connected.")
212222

223+
def unregister(self):
224+
# We have to hold the registration lock if the client is callable
225+
# to avoid a race condition where the client queries the hub for
226+
# pushCallbacks after it has already been unregistered from the hub
227+
with self._registration_lock:
228+
super().unregister()
229+
213230

214231
class SAMPIntegratedWebClient(SAMPIntegratedClient):
215232
"""

0 commit comments

Comments
 (0)