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
// on the local interface by other apps.
assertApproxEquals(
ifaceTxBytes, newIfaceTxBytes, expectedTxByteDelta, ERROR_MARGIN_BYTES);
assertApproxEquals(
ifaceRxBytes, newIfaceRxBytes, expectedRxByteDelta, ERROR_MARGIN_BYTES);
assertApproxEquals(
ifaceTxPackets, newIfaceTxPackets, expectedTxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals(
ifaceRxPackets, newIfaceRxPackets, expectedRxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals("TX bytes", ifaceTxBytes, newIfaceTxBytes, expectedTxByteDelta,
ERROR_MARGIN_BYTES);
assertApproxEquals("RX bytes", ifaceRxBytes, newIfaceRxBytes, expectedRxByteDelta,
ERROR_MARGIN_BYTES);
assertApproxEquals("TX packets", ifaceTxPackets, newIfaceTxPackets,
expectedTxPacketDelta, ERROR_MARGIN_PKTS);
assertApproxEquals("RX packets", ifaceRxPackets, newIfaceRxPackets,
expectedRxPacketDelta, ERROR_MARGIN_PKTS);
}
private static void assertApproxEquals(
long oldStats, long newStats, int expectedDelta, double errorMargin) {
assertTrue(expectedDelta <= newStats - oldStats);
assertTrue((expectedDelta * errorMargin) > newStats - oldStats);
String what, long oldStats, long newStats, int expectedDelta, double errorMargin) {
assertTrue(
"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 {