Merge "Include the failing stats in stats failure assertions."

This commit is contained in:
Treehugger Robot
2021-11-08 06:20:39 +00:00
committed by Gerrit Code Review

View File

@@ -413,20 +413,26 @@ public class IpSecManagerTest extends IpSecBaseTest {
// Check that iface stats are within an acceptable range; data might be sent // Check that iface stats are within an acceptable range; data might be sent
// on the local interface by other apps. // on the local interface by other apps.
assertApproxEquals( assertApproxEquals("TX bytes", ifaceTxBytes, newIfaceTxBytes, expectedTxByteDelta,
ifaceTxBytes, newIfaceTxBytes, expectedTxByteDelta, ERROR_MARGIN_BYTES); ERROR_MARGIN_BYTES);
assertApproxEquals( assertApproxEquals("RX bytes", ifaceRxBytes, newIfaceRxBytes, expectedRxByteDelta,
ifaceRxBytes, newIfaceRxBytes, expectedRxByteDelta, ERROR_MARGIN_BYTES); ERROR_MARGIN_BYTES);
assertApproxEquals( assertApproxEquals("TX packets", ifaceTxPackets, newIfaceTxPackets,
ifaceTxPackets, newIfaceTxPackets, expectedTxPacketDelta, ERROR_MARGIN_PKTS); expectedTxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals( assertApproxEquals("RX packets", ifaceRxPackets, newIfaceRxPackets,
ifaceRxPackets, newIfaceRxPackets, expectedRxPacketDelta, ERROR_MARGIN_PKTS); expectedRxPacketDelta, ERROR_MARGIN_PKTS);
} }
private static void assertApproxEquals( private static void assertApproxEquals(
long oldStats, long newStats, int expectedDelta, double errorMargin) { String what, long oldStats, long newStats, int expectedDelta, double errorMargin) {
assertTrue(expectedDelta <= newStats - oldStats); assertTrue(
assertTrue((expectedDelta * errorMargin) > newStats - oldStats); "Expected at least " + expectedDelta + " " + what
+ ", got " + (newStats - oldStats),
newStats - oldStats >= expectedDelta);
assertTrue(
"Expected at most " + errorMargin + " * " + expectedDelta + " " + what
+ ", got " + (newStats - oldStats),
newStats - oldStats < (expectedDelta * errorMargin));
} }
private static void initStatsChecker() throws Exception { private static void initStatsChecker() throws Exception {