From ebaef1230baf06c84bcfc33faff7d2636727b110 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Fri, 9 May 2025 13:20:31 +0900 Subject: [PATCH] Don't ignore exceptions in NsdManagerDownstreamTetheringTest tryTest{} catches and returns and must be ended with a cleanup{} block to throw. That is why it's marked with @CheckReturnValue. The IDE marks the entire block as a huge warning. Ideally this should really be an error, but that flag only exists in Kotlin 2.2 and above, which is not out of beta yet, so add a TODO in the bp file Test: NsdManagerDownstreamTetheringTest Flag: EXEMPT test-only Change-Id: I62a9d0a16926574eb286d45b61d4d5d2e8c870ab --- tests/common/Android.bp | 2 ++ .../src/android/net/cts/NsdManagerDownstreamTetheringTest.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/common/Android.bp b/tests/common/Android.bp index 1600a6a0ec..4ecb23c043 100644 --- a/tests/common/Android.bp +++ b/tests/common/Android.bp @@ -158,6 +158,7 @@ java_defaults { // Tests must check a large number of deprecated methods and warning about it // sends hundreds of warning lines flooding the useful warnings. kotlincflags: ["-Xsuppress-warning=DEPRECATION"], + // TODO: add "-Xwarning-level=CheckResult:error" when Kotlin 2.2.0 is out } // defaults for tests that need to build against framework-connectivity's @hide APIs, but also @@ -184,6 +185,7 @@ java_defaults { // Tests must check a large number of deprecated methods and warning about it // sends hundreds of warning lines flooding the useful warnings. kotlincflags: ["-Xsuppress-warning=DEPRECATION"], + // TODO: add "-Xwarning-level=CheckResult:error" when Kotlin 2.2.0 is out defaults_visibility: ["//packages/modules/Connectivity/tests:__subpackages__"], } diff --git a/tests/cts/net/src/android/net/cts/NsdManagerDownstreamTetheringTest.kt b/tests/cts/net/src/android/net/cts/NsdManagerDownstreamTetheringTest.kt index 19a40f9502..97556f54a2 100644 --- a/tests/cts/net/src/android/net/cts/NsdManagerDownstreamTetheringTest.kt +++ b/tests/cts/net/src/android/net/cts/NsdManagerDownstreamTetheringTest.kt @@ -104,7 +104,7 @@ class NsdManagerDownstreamTetheringTest : EthernetTetheringTestBase() { nsdManager.discoverServices(serviceType, NsdManager.PROTOCOL_DNS_SD, discoveryRecord) discoveryRecord.expectCallback() assertNotNull(downstreamReader.pollForQuery("$serviceType.local", 12 /* type PTR */)) - } cleanupStep { + } cleanup { nsdManager.stopServiceDiscovery(discoveryRecord) discoveryRecord.expectCallback() } @@ -137,7 +137,7 @@ class NsdManagerDownstreamTetheringTest : EthernetTetheringTestBase() { val downstreamReader = downstreamIface.packetReader assertNotNull(downstreamReader.pollForQuery("$serviceType.local", 12 /* type PTR */)) // TODO: Add another test to check packet reply can trigger serviceFound. - } cleanupStep { + } cleanup { nsdManager.stopServiceDiscovery(discoveryRecord) discoveryRecord.expectCallback() }