Fix deadlock between endpoint and video status queries
This commit is contained in:
@@ -61,6 +61,19 @@ class EndpointTests(unittest.TestCase):
|
||||
def request(self,path='/v1/models',data=None,token='A'*32):
|
||||
conn=http.client.HTTPConnection('127.0.0.1',self.port,timeout=5);headers={'Content-Type':'application/json','Authorization':'Bearer '+token}
|
||||
conn.request('POST' if data is not None else 'GET',path,body=json.dumps(data) if data is not None else None,headers=headers);r=conn.getresponse();body=r.read();conn.close();return r.status,(body if data and data.get('stream') else json.loads(body))
|
||||
def test_status_allows_video_callback_to_read_endpoint_from_other_thread(self):
|
||||
finished=threading.Event();readers=[]
|
||||
def video_status():
|
||||
def read_profiles():
|
||||
self.ep.rows();finished.set()
|
||||
reader=threading.Thread(target=read_profiles,daemon=True);readers.append(reader);reader.start()
|
||||
self.assertTrue(finished.wait(1),'Endpoint lock blocks concurrent video/profile status queries')
|
||||
return {'service':{}}
|
||||
self.ep.video=Mock();self.ep.video.status.side_effect=video_status
|
||||
try:self.ep.status()
|
||||
finally:
|
||||
self.ep.video=None
|
||||
for reader in readers:reader.join(2)
|
||||
def test_music_discovery_and_authenticated_wav_route(self):
|
||||
self.rows.append(dict(id='music',name='Music',kind='music',runnable=True,blockers=[],parameters={},updated_at=1))
|
||||
self.ep.music=Mock();self.ep.music.start.return_value=dict(id='a'*32);self.ep.music.status.return_value=dict(job=dict(id='a'*32,state='complete'));self.ep.music.audio.return_value=b'RIFFsynthetic-WAV'
|
||||
|
||||
Reference in New Issue
Block a user