Skip to content

Commit

Permalink
Fixes logcat regex issue
Browse files Browse the repository at this point in the history
  • Loading branch information
odmnk committed May 7, 2021
1 parent 2d33a8f commit ece9da0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions AndroidRunner/Script.py
Expand Up @@ -2,7 +2,7 @@
import multiprocessing as mp
import os.path as op
import signal

import time
from . import Tests
from .util import FileNotFoundError

Expand Down Expand Up @@ -42,7 +42,8 @@ def mp_logcat_regex(queue, device, regex):
"""The multiprocessing wrapper of Device.logcat_regex()"""
# https://stackoverflow.com/a/21936682
# pyadb uses subprocess.communicate(), therefore it blocks
device.logcat_regex(regex)
while not device.logcat_regex(regex):
time.sleep(1)
queue.put('logcat')

def run(self, device, *args, **kwargs):
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/test_scripts.py
Expand Up @@ -3,7 +3,7 @@

import pytest
from mock import Mock, call, patch

import time
import paths
from AndroidRunner.MonkeyReplay import MonkeyReplay, MonkeyReplayError
from AndroidRunner.MonkeyRunner import MonkeyRunner
Expand Down Expand Up @@ -287,3 +287,14 @@ def test_script_mp_run_error(self, error_script_path):
assert test_queue.put.call_count == 2
assert 'NotImplementedError' in str(test_queue.put.call_args_list)
assert 'script' in str(test_queue.put.call_args_list[1][0])

@patch("time.sleep")
def test_mp_logcat_regex_one_iteration(self, sleep, script_path):
fake_device = Mock()
fake_device.logcat_regex.side_effect = [False, True]
test_queue = Mock()
test_script = Python3(script_path)
test_script.mp_logcat_regex(test_queue, fake_device, "Test")

sleep.assert_called_once_with(1)
test_queue.put.assert_called_once_with("logcat")

0 comments on commit ece9da0

Please sign in to comment.