Skip to content

Commit

Permalink
Merge pull request #448 from raoyitao/fix_pool_exit_msg
Browse files Browse the repository at this point in the history
Fix Newly created worker may raise when pool is exiting
  • Loading branch information
raoyitao committed Jun 22, 2020
2 parents 4cef891 + 13f139d commit 10bd5af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 5 additions & 1 deletion testplan/runners/pools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def _query_worker_status(self, worker):
worker.status.STOPPING,
worker.status.STOPPED,
):
return "inactive", "Worker in stop/abort status"
return "inactive", "Worker {} in stop/abort status"

if worker.status.tag in (worker.status.NONE, worker.status.STARTING):
return "initializing", None
Expand Down Expand Up @@ -700,9 +700,13 @@ def _query_worker_status(self, worker):
def _handle_inactive(self, worker, reason):
"""
Handle an inactive worker.
:param worker: worker object
:type worker: :py:class:`~testplan.runners.pool.base.Worker`
:param reason: why worker is considered inactive
:type reason: ``str``
:return: True if worker restarted, else False
:rtype: ``bool``
"""
if worker.status.tag != worker.status.STARTED:
return False
Expand Down
11 changes: 9 additions & 2 deletions testplan/runners/pools/child.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import signal
import socket
import shutil
import inspect
import logging
import argparse
import platform
Expand Down Expand Up @@ -144,9 +143,17 @@ def _send_and_expect(self, message, send, expect):

def _pre_loop_setup(self, message):
response = self._send_and_expect(
message, message.ConfigRequest, message.ConfigSending
message,
message.ConfigRequest,
[message.ConfigSending, message.Stop],
)

# Process pool might be exiting after worker restarts and tries
# to connect, at this time worker can gracefully exit.
if response.cmd == message.Stop:
self.logger.debug("Stop message received, child exits.")
os._exit(0)

# Response.data: [cfg, cfg.parent, cfg.parent.parent, ...]
pool_cfg = response.data[0]
for idx, cfg in enumerate(response.data):
Expand Down
9 changes: 6 additions & 3 deletions testplan/runners/pools/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def send_and_receive(self, message, expect=None):
:param message: Message sent.
:type message:
:py:class:`~testplan.runners.pools.communication.Message`
:param expect: Assert message received command is the expected.
:type expect: ``NoneType`` or
:param expect: Expected command of message received.
:type expect: ``NoneType`` or ``tuple`` or ``list`` or
:py:class:`~testplan.runners.pools.communication.Message`
:return: Message received.
:rtype: ``object``
Expand All @@ -82,7 +82,10 @@ def send_and_receive(self, message, expect=None):
raise RuntimeError(
"Received None when {} was expected.".format(expect)
)
assert received.cmd == expect
if isinstance(expect, (tuple, list)):
assert received.cmd in expect
else:
assert received.cmd == expect
return received


Expand Down

0 comments on commit 10bd5af

Please sign in to comment.