From 2bcd523745bb7c6cc5140ffb6d97bcfd897e7a52 Mon Sep 17 00:00:00 2001 From: Wayne Ma Date: Tue, 21 Mar 2023 11:36:07 +0800 Subject: [PATCH] Add new test for swtiching multiple upstream network. Bug: 263681262 Test: atest TetheringMetricsTest Change-Id: I70e88d36ecf4cac0f61ab54cc14efa46a4b5facb --- .../metrics/TetheringMetricsTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java index a570736745..aa2d16ca68 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/metrics/TetheringMetricsTest.java @@ -361,4 +361,30 @@ public final class TetheringMetricsTest { UserType.USER_SETTINGS, wifiTetheringUpstreamEvents, currentTimeMillis() - wifiTetheringStartTime); } + + @Test + public void testSwitchingMultiUpstreams() throws Exception { + mTetheringMetrics.createBuilder(TETHERING_WIFI, SETTINGS_PKG); + final long wifiTetheringStartTime = currentTimeMillis(); + incrementCurrentTime(1 * SECOND_IN_MILLIS); + mTetheringMetrics.maybeUpdateUpstreamType(buildUpstreamState(TRANSPORT_WIFI)); + final long wifiDuration = 5 * SECOND_IN_MILLIS; + incrementCurrentTime(wifiDuration); + mTetheringMetrics.maybeUpdateUpstreamType(buildUpstreamState(TRANSPORT_BLUETOOTH)); + final long bluetoothDuration = 15 * SECOND_IN_MILLIS; + incrementCurrentTime(bluetoothDuration); + mTetheringMetrics.maybeUpdateUpstreamType(buildUpstreamState(TRANSPORT_CELLULAR)); + final long celltoothDuration = 20 * SECOND_IN_MILLIS; + incrementCurrentTime(celltoothDuration); + updateErrorAndSendReport(TETHERING_WIFI, TETHER_ERROR_NO_ERROR); + + UpstreamEvents.Builder upstreamEvents = UpstreamEvents.newBuilder(); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_WIFI, wifiDuration); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_BLUETOOTH, bluetoothDuration); + addUpstreamEvent(upstreamEvents, UpstreamType.UT_CELLULAR, celltoothDuration); + + verifyReport(DownstreamType.DS_TETHERING_WIFI, ErrorCode.EC_NO_ERROR, + UserType.USER_SETTINGS, upstreamEvents, + currentTimeMillis() - wifiTetheringStartTime); + } }