google / mobly

E2E test framework for tests with complex environment requirements.
https://github.com/google/mobly
Apache License 2.0
627 stars 175 forks source link

Mobly exits without cleaning resources if receives a SIGTERM signal #797

Closed mhaoli closed 1 year ago

mhaoli commented 2 years ago

Currently, Mobly won't clean requested resources if receives a SIGTERM signal.

We can use a simple test to reproduce the bug:

import logging
import os
from mobly import base_test
from mobly import test_runner
from mobly.controllers import android_device

class SingleTest(base_test.BaseTestClass):
  def setup_class(self):
    self.dut = self.register_controller(android_device)[0]
    self.dut.load_snippet('mbs', 'com.google.android.mobly.snippet.example1')
    self._get_snippet_client_info()
    logging.info('pid of the whole test process: %d', os.getpid())

  def test_sleep_and_send_rpc_multiple_times(self):
    import signal
    signal.raise_signal(signal.SIGTERM)
    logging.info("Won't run on this line.")

  def _get_snippet_client_info(self):
    self.client_port = self.dut.mbs.host_port
    self.client_pid = self.dut.mbs._proc.pid
    logging.info('single_test_client_host_port: %d.' % self.dut.mbs.host_port)
    logging.info('single_test_client_pid: %d.' % self.dut.mbs._proc.pid)

if __name__ == '__main__':
  test_runner.main()

The running log shows that Mobly doesn't clean the following resources: logcat service processes, server processes, ports used for adb forwarding.

Screenshot from 2022-02-23 19-24-23