                     {:name "non-empty-inputs-c", :input {:old [:a :b], :new [:b :c :d :e], :initial 3}, :expected 5}
                     {:name "non-empty-inputs-d", :input {:old [:a :b :c], :new [:d], :initial 3}, :expected 1}]]
     (doseq [test-case test-cases]
-      (let [{:keys [name input expected]} test-case
-            title ["waiter" "test" name]
-            counter (counters/counter title)]
-        (testing (str "Test " name)
-          (if (:initial input)
-            (do
-              (counters/clear! counter)
-              (counters/inc! counter (:initial input))))
-          (update-counter counter (:old input) (:new input))
-          (let [actual-value (counters/value counter)]
-            (is (= expected actual-value))))))))
+      (with-isolated-registry
+        (let [{:keys [name input expected]} test-case
+              title ["waiter" "test" name]
+              counter (counters/counter title)]
+          (testing (str "Test " name)
+            (if (:initial input)
+              (do
+                (counters/clear! counter)
+                (counters/inc! counter (:initial input))))
+            (update-counter counter (:old input) (:new input))
+            (let [actual-value (counters/value counter)]
+              (is (= expected actual-value)))))))))
 
 (deftest test-reset-counter
   (let [test-cases [{:name "nil-inputs", :initial nil, :input nil, :expected 0}

                    {:name "old-counter-nil-input", :initial 2, :input nil, :expected 0}]]
    (doseq [{:keys [name initial input expected]} test-cases]
      (testing (str "Test " name)
        (let [title ["waiter" "test" name]
              the-counter (counters/counter title)]
          (when initial
            (counters/clear! the-counter)
            (counters/inc! the-counter initial))
          (reset-counter the-counter input)
          (let [actual-value (counters/value the-counter)]
            (is (= expected actual-value))))))))

(deftest test-prefix-and-contains-metrics-filter
  (with-isolated-registry

    (is (= expected actual))))

(deftest test-remove-and-check-metrics-except-outstanding
  (with-isolated-registry
    (let [metrics-registry mc/default-registry
          create-metrics (fn [service-id]
                           (histograms/update! (histograms/histogram ["services" service-id "test-histogram1"]) (hash service-id))
                           (histograms/update! (histograms/histogram ["services" service-id "instance" "test-histogram2"]) (hash service-id))
                           (timers/start-stop-time! (timers/timer ["services" service-id "test-response-duration"]))
                           (timers/start-stop-time! (timers/timer ["services" service-id "nested" "test-response-duration"]))
                           (meters/mark! (meters/meter ["services" service-id "test-throughput"]))
                           (meters/mark! (meters/meter ["services" service-id "nested" "test-throughput"]))
                           (counters/inc! (counters/counter ["services" service-id "foo" "bar"]))
                           (counters/inc! (counters/counter ["services" service-id "outstanding" "fum"])))
          metrics-per-service 8
          has-metrics-except-outstanding? (fn has-metrics-except-outstanding? [service-id]
                                            (let [metric-filter (reify MetricFilter
                                                                  (matches [_ name _]
                                                                    (and (str/includes? name service-id)
                                                                         (not (str/includes? name "outstanding")))))]
                                              (or (not-empty (.getCounters metrics-registry metric-filter))
                                                  (not-empty (.getHistograms metrics-registry metric-filter))
                                                  (not-empty (.getMeters metrics-registry metric-filter))
                                                  (not-empty (.getTimers metrics-registry metric-filter)))))]
      (testing "Delete metrics for specified services"
        (.removeMatching metrics-registry (reify MetricFilter (matches [_ _ _] true)))
        (let [metrics-items (.getMetrics metrics-registry)]
          (is (zero? (count metrics-items)) (str metrics-items)))
        (create-metrics "test-service-1")
        (create-metrics "test-service-2")
        (create-metrics "test-service-3")
        (let [metrics-items (.getMetrics metrics-registry)]
          (is (= (* 3 metrics-per-service) (count metrics-items)) (str metrics-items)))
        (create-metrics "test-service-2")
        (let [metrics-items (.getMetrics metrics-registry)]
          (is (= (* 3 metrics-per-service) (count metrics-items)) (str metrics-items)))
        (create-metrics "test-service-1")
        (let [metrics-items (.getMetrics metrics-registry)]
          (is (= (* 3 metrics-per-service) (count metrics-items)) (str metrics-items)))
        (is (has-metrics-except-outstanding? "test-service-1"))
        (is (has-metrics-except-outstanding? "test-service-2"))
        (is (has-metrics-except-outstanding? "test-service-3"))
        (remove-metrics-except-outstanding metrics-registry "test-service-1")
        (let [metrics-items (.getMetrics metrics-registry)]
          (is (= (+ (* 1 1) (* 2 metrics-per-service)) (count metrics-items)) (str metrics-items)))
        (is (not (has-metrics-except-outstanding? "test-service-1")))
        (is (has-metrics-except-outstanding? "test-service-2"))
        (is (has-metrics-except-outstanding? "test-service-3"))
        (remove-metrics-except-outstanding metrics-registry "test-service-2")
        (let [metrics-items (.getMetrics metrics-registry)]
          (is (= (+ (* 2 1) (* 1 metrics-per-service)) (count metrics-items)) (str metrics-items)))
        (is (not (has-metrics-except-outstanding? "test-service-1")))
        (is (not (has-metrics-except-outstanding? "test-service-2")))
        (is (has-metrics-except-outstanding? "test-service-3"))
        (.removeMatching metrics-registry (reify MetricFilter (matches [_ _ _] true)))))))

(deftest test-transient-metrics-data-producer
  (let [service-id->metrics-atom (atom {})
