Ensure consistent payload comparison by sorting
The device may transmit multiple packets in the order different from what is programmed in the APF.
This can lead to flaky test results due to variations in the payload order.
Bug: 391468682
Test: atest CtsNetTestCases:android.net.cts.ApfIntegrationTest#testReplyPing
Change-Id: I1ee298e69137282a7f1c570711d29d0a930ce718
diff --git a/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt b/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
index 3ab6c0d..2af4890 100644
--- a/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
+++ b/tests/cts/net/src/android/net/cts/ApfIntegrationTest.kt
@@ -799,8 +799,12 @@
Log.i(TAG, "counter map: ${apfCounterTracker.counters}")
assertThat(replyPayloads.size).isEqualTo(expectReplyPayloads.size)
- for (i in replyPayloads.indices) {
- assertThat(replyPayloads[i]).isEqualTo(expectReplyPayloads[i])
+
+ // Sort the payload list before comparison to ensure consistency.
+ val sortedReplyPayloads = replyPayloads.sortedBy { it[0] }
+ val sortedExpectReplyPayloads = expectReplyPayloads.sortedBy { it[0] }
+ for (i in sortedReplyPayloads.indices) {
+ assertThat(sortedReplyPayloads[i]).isEqualTo(sortedExpectReplyPayloads[i])
}
}
}