Skip to content

Commit

Permalink
Added test_worker_closed
Browse files Browse the repository at this point in the history
  • Loading branch information
huashengdun committed Nov 21, 2022
1 parent 9238c01 commit 50fc990
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,21 @@ def __call__(self):
WsockHandler.on_message(obj, b'{"data": "somestuff"}')
self.assertGreaterEqual(ref.count, 1)
obj.close.assert_called_with(reason='No worker found')

def test_worker_closed(self):
request = HTTPServerRequest(uri='/')
obj = Mock(spec=WsockHandler, request=request)
obj.src_addr = ("127.0.0.1", 8888)

class Worker:
def __init__(self):
self.closed = True

class FakeWeakRef:
def __call__(self):
return Worker()

ref = FakeWeakRef()
obj.worker_ref = ref
WsockHandler.on_message(obj, b'{"data": "somestuff"}')
obj.close.assert_called_with(reason='Worker closed')

0 comments on commit 50fc990

Please sign in to comment.