Merge "Include the failing stats in stats failure assertions."
This commit is contained in:
commit
27979bd116
1 changed files with 17 additions and 11 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue