From 50f3ea269bf40004709176f6219c81cae19fcff3 Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Fri, 1 May 2026 08:08:04 -0700 Subject: [PATCH] [fix][test] Fix flaky SchemaServiceTest.testSchemaRegistryMetrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pulsar_schema_*_ops_failed_total counters in SchemaRegistryStats are registered on the default Prometheus registry — a JVM-wide static. Labels accumulated by other tests (or by broker-internal failed gets unrelated to this test) survive across @BeforeMethod broker restarts, so asserting collection.size() == 0 fails whenever any prior code path observed a failed op. Filter the assertion to the test's own namespace: noneMatch metric where namespace tag equals the test's namespace. Catches the bug the test was meant to catch (this test's ops shouldn't increment failed counters) without being polluted by global counter state. --- .../broker/service/schema/SchemaServiceTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/SchemaServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/SchemaServiceTest.java index d164559e85858..757dfd827ff52 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/SchemaServiceTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/schema/SchemaServiceTest.java @@ -173,12 +173,16 @@ public void testSchemaRegistryMetrics() throws Exception { String metricsStr = output.toString(StandardCharsets.UTF_8); Multimap metrics = parseMetrics(metricsStr); + // The *_ops_failed_total counters are registered on the default Prometheus + // registry (a JVM-wide static), so labels accumulated by other tests in the + // same JVM persist here. Only assert that no failed metric exists for THIS + // test's namespace. Collection delMetrics = metrics.get("pulsar_schema_del_ops_failed_total"); - Assert.assertEquals(delMetrics.size(), 0); + assertThat(delMetrics).noneMatch(metric -> namespace.equals(metric.tags.get("namespace"))); Collection getMetrics = metrics.get("pulsar_schema_get_ops_failed_total"); - Assert.assertEquals(getMetrics.size(), 0); + assertThat(getMetrics).noneMatch(metric -> namespace.equals(metric.tags.get("namespace"))); Collection putMetrics = metrics.get("pulsar_schema_put_ops_failed_total"); - Assert.assertEquals(putMetrics.size(), 0); + assertThat(putMetrics).noneMatch(metric -> namespace.equals(metric.tags.get("namespace"))); Collection deleteLatency = metrics.get("pulsar_schema_del_ops_latency_count"); assertThat(deleteLatency).anySatisfy(metric -> {