From ca4c04bb08449eb4b52e68e1e3906185093bde09 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Thu, 12 Feb 2015 16:51:28 -0800 Subject: [PATCH] Add test to confirm that bad requests do not affect circuit breaker's computer error percentage --- .../hystrix/HystrixCommandMetricsTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandMetricsTest.java b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandMetricsTest.java index f8e6aea99..3bfaffb86 100644 --- a/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandMetricsTest.java +++ b/hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandMetricsTest.java @@ -70,6 +70,26 @@ public void testGetErrorPercentage() { } + @Test + public void testBadRequestsDoNotAffectErrorPercentage() { + HystrixCommandProperties.Setter properties = HystrixCommandPropertiesTest.getUnitTestPropertiesSetter(); + HystrixCommandMetrics metrics = getMetrics(properties); + + metrics.markSuccess(100); + assertEquals(0, metrics.getHealthCounts().getErrorPercentage()); + + metrics.markFailure(1000); + assertEquals(50, metrics.getHealthCounts().getErrorPercentage()); + + metrics.markBadRequest(1); + metrics.markBadRequest(2); + assertEquals(50, metrics.getHealthCounts().getErrorPercentage()); + + metrics.markFailure(45); + metrics.markFailure(55); + assertEquals(75, metrics.getHealthCounts().getErrorPercentage()); + } + /** * Utility method for creating {@link HystrixCommandMetrics} for unit tests. */