fix: 采集商品页轮询避开慢速前台查询 (#115)
This commit is contained in:
@@ -35,9 +35,11 @@ class FakeCollectDevice:
|
||||
self.swipes = []
|
||||
self.swipe_panel_states = []
|
||||
self.app_wait_calls = 0
|
||||
self.app_current_calls = 0
|
||||
self.opened_url = None
|
||||
|
||||
def app_current(self):
|
||||
self.app_current_calls += 1
|
||||
return {"package": "com.xunmeng.pinduoduo"}
|
||||
|
||||
def app_start(self, _package):
|
||||
@@ -94,13 +96,13 @@ class LoadingDevice(FakeCollectDevice):
|
||||
class DisconnectingDevice(FakeCollectDevice):
|
||||
def __init__(self, home_xml, spec_xml):
|
||||
super().__init__(home_xml, spec_xml)
|
||||
self.current_calls = 0
|
||||
self.hierarchy_calls = 0
|
||||
|
||||
def app_current(self):
|
||||
self.current_calls += 1
|
||||
if self.current_calls > 1:
|
||||
def dump_hierarchy(self):
|
||||
self.hierarchy_calls += 1
|
||||
if self.hierarchy_calls > 1:
|
||||
raise RuntimeError("device not found")
|
||||
return super().app_current()
|
||||
return super().dump_hierarchy()
|
||||
|
||||
|
||||
class FocusMismatchDevice(FakeCollectDevice):
|
||||
@@ -113,6 +115,18 @@ class FocusMismatchDevice(FakeCollectDevice):
|
||||
self.app_started = True
|
||||
|
||||
|
||||
class SlowFocusMismatchDevice(FocusMismatchDevice):
|
||||
def __init__(self, home_xml, spec_xml, clock):
|
||||
super().__init__(home_xml, spec_xml)
|
||||
self.clock = clock
|
||||
self.app_current_calls = 0
|
||||
|
||||
def app_current(self):
|
||||
self.app_current_calls += 1
|
||||
self.clock.sleep(11.0)
|
||||
return {"package": "com.android.settings"}
|
||||
|
||||
|
||||
class PanelDoesNotOpenDevice(FakeCollectDevice):
|
||||
def click(self, x, y):
|
||||
self.clicks.append((x, y))
|
||||
@@ -434,6 +448,7 @@ class PddCollectParserTest(unittest.TestCase):
|
||||
self.assertEqual(data["source"]["device_address"], "USB-001")
|
||||
self.assertIsNone(data["purchase"])
|
||||
self.assertEqual(device.app_wait_calls, 0)
|
||||
self.assertEqual(device.app_current_calls, 1)
|
||||
|
||||
def test_collect_scrolls_before_spec_panel_and_accumulates_metadata(self):
|
||||
initial_page = self.home_xml.replace(
|
||||
@@ -823,6 +838,28 @@ class PddCollectParserTest(unittest.TestCase):
|
||||
self.assertEqual(2, raised.exception.diagnostics["open_attempts"])
|
||||
self.assertEqual([], device.clicks)
|
||||
|
||||
def test_slow_wrong_focus_does_not_consume_home_reopen_timeout(self):
|
||||
home = (FIXTURES / "pdd_home_page.xml").read_text(encoding="utf-8")
|
||||
clock = FakeClock()
|
||||
device = SlowFocusMismatchDevice(home, self.spec_xml, clock)
|
||||
service = PddCollectService(
|
||||
PddDeviceService(lambda _serial: device),
|
||||
"USB-001",
|
||||
"client-001",
|
||||
sleeper=clock.sleep,
|
||||
monotonic=clock.monotonic,
|
||||
page_timeout=10.0,
|
||||
)
|
||||
|
||||
with self.assertRaises(PddCollectError) as raised:
|
||||
service.collect(
|
||||
FakeTask("https://mobile.yangkeduo.com/goods.html?goods_id=123")
|
||||
)
|
||||
|
||||
self.assertEqual("PDD_GOODS_UNAVAILABLE", raised.exception.code)
|
||||
self.assertEqual(1, device.app_current_calls)
|
||||
self.assertEqual([], device.clicks)
|
||||
|
||||
def test_non_pdd_tree_with_purchase_words_is_not_ready(self):
|
||||
device = FocusMismatchDevice(
|
||||
'<hierarchy><node package="com.android.settings" text="免拼购买" '
|
||||
|
||||
Reference in New Issue
Block a user