Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d72af4a3 authored by Christine Hallstrom's avatar Christine Hallstrom
Browse files

Fix flakiness in LeAdvancedScanningTest lost test

Wait for scan result match found event to ensure scanner is started before stopping advertiser to generate lost match event. Otherwise the scanner may not have started before advertising stops on the cert side and the test may fail to catch it.

Bug: 232424520
Test: gd/cert/run --device --clean --sl4a
LeAdvancedScanningTest.test_scan_filter_lost_random_address_with_irk
--repeat=10
Ignore-AOSP-First: Fixing flakiness on tests needed for presubmit on
tm-dev.

Change-Id: Id7957d989ffc95c7c869132d1f059957f5720fe2
parent 71f951b4
Loading
Loading
Loading
Loading
+9 −11
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


import queue
import queue
import logging
import logging
import _thread
import time


from google.protobuf import empty_pb2 as empty_proto
from google.protobuf import empty_pb2 as empty_proto


@@ -698,7 +696,7 @@ class LeAdvancedScanningTest(gd_sl4a_base_test.GdSl4aBaseTestClass):
                     (RANDOM_ADDRESS, addr_type, self.__get_test_irk().decode("utf-8")))
                     (RANDOM_ADDRESS, addr_type, self.__get_test_irk().decode("utf-8")))
        self.dut.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
        self.dut.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
        self.dut.sl4a.bleSetScanSettingsLegacy(False)
        self.dut.sl4a.bleSetScanSettingsLegacy(False)
        self.dut.sl4a.bleSetScanSettingsCallbackType(ble_scan_settings_callback_types['match_lost'])
        self.dut.sl4a.bleSetScanSettingsCallbackType(ble_scan_settings_callback_types['found_and_lost'])
        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(self.dut.sl4a)
        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(self.dut.sl4a)
        expected_event_name = scan_result.format(scan_callback)
        expected_event_name = scan_result.format(scan_callback)


@@ -709,16 +707,16 @@ class LeAdvancedScanningTest(gd_sl4a_base_test.GdSl4aBaseTestClass):
        self.dut.sl4a.bleStartBleScan(filter_list, scan_settings, scan_callback)
        self.dut.sl4a.bleStartBleScan(filter_list, scan_settings, scan_callback)
        logging.info("Started scanning")
        logging.info("Started scanning")


        def run(test, delay):
        # Wait for found event to ensure scanning is started before stopping the advertiser
            time.sleep(delay)
        # to trigger lost event, else the lost event might not be caught by the test
            # Stop advertising to trigger the lost event
        got_found_result = self._wait_for_scan_result_event(expected_event_name)
            test._stop_advertising(create_response.advertiser_id)
        assertThat(got_found_result).isTrue()


        _thread.start_new_thread(run, (self, 3))
        self._stop_advertising(create_response.advertiser_id)


        # Wait for results
        # Wait for lost event
        got_result = self._wait_for_scan_result_event(expected_event_name)
        got_lost_result = self._wait_for_scan_result_event(expected_event_name)
        assertThat(got_result).isTrue()
        assertThat(got_lost_result).isTrue()


        # Test over
        # Test over
        self._stop_scanning(scan_callback)
        self._stop_scanning(scan_callback)