Improve discovery
1) Add random delay between startAdvertising and startDsicovery
2) Increase discovery timeout to 30s / 35s for 1st / 2nd connection.
Bug: 301453743
Test: performance test
Change-Id: I478442a24aa06892e3a29f473bdaef4540fcd050
diff --git a/tests/bettertogether/quickstart/performance_test/nc_constants.py b/tests/bettertogether/quickstart/performance_test/nc_constants.py
index 4d9228c..c839cf0 100644
--- a/tests/bettertogether/quickstart/performance_test/nc_constants.py
+++ b/tests/bettertogether/quickstart/performance_test/nc_constants.py
@@ -21,11 +21,11 @@
NEARBY_RESET_WAIT_TIME = datetime.timedelta(seconds=5)
WIFI_DISCONNECTION_DELAY = datetime.timedelta(seconds=3)
-FIRST_DISCOVERY_TIMEOUT = datetime.timedelta(seconds=15)
+FIRST_DISCOVERY_TIMEOUT = datetime.timedelta(seconds=30)
FIRST_CONNECTION_INIT_TIMEOUT = datetime.timedelta(seconds=30)
FIRST_CONNECTION_RESULT_TIMEOUT = datetime.timedelta(seconds=35)
FILE_1M_PAYLOAD_TRANSFER_TIMEOUT = datetime.timedelta(seconds=110)
-SECOND_DISCOVERY_TIMEOUT = datetime.timedelta(seconds=25)
+SECOND_DISCOVERY_TIMEOUT = datetime.timedelta(seconds=35)
SECOND_CONNECTION_INIT_TIMEOUT = datetime.timedelta(seconds=10)
SECOND_CONNECTION_RESULT_TIMEOUT = datetime.timedelta(seconds=25)
CONNECTION_BANDWIDTH_CHANGED_TIMEOUT = datetime.timedelta(seconds=25)
diff --git a/tests/bettertogether/quickstart/performance_test/nearby_connection_wrapper.py b/tests/bettertogether/quickstart/performance_test/nearby_connection_wrapper.py
index 8cc6627..90529b4 100644
--- a/tests/bettertogether/quickstart/performance_test/nearby_connection_wrapper.py
+++ b/tests/bettertogether/quickstart/performance_test/nearby_connection_wrapper.py
@@ -15,6 +15,8 @@
"""Utils for handling Nearby Connection rpc."""
import datetime
+import random
+import time
from mobly import asserts
from mobly import utils
@@ -25,6 +27,10 @@
from performance_test import nc_constants
+# This number should be large enough to cover advertising interval, firmware
+# scheduling timing interval and user action delay
+ADVERTISING_TO_DISCOVERY_MAX_DELAY_SEC = 4
+
class NearbyConnectionWrapper:
"""Wrapper for Nearby Connection Snippet Client Operations."""
@@ -289,6 +295,10 @@
# Start advertising.
self.start_advertising()
+ # Add a random delay between adversting and discovery
+ # to mimic the random delay between two devices' user action
+ time.sleep(ADVERTISING_TO_DISCOVERY_MAX_DELAY_SEC * random.random())
+
# Start discovery.
self.start_discovery(timeout=timeouts.discovery_timeout)