You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wa...@apache.org on 2026/08/04 06:29:00 UTC

(skywalking) branch MAL-test created (now 564ebee42a)

This is an automated email from the ASF dual-hosted git repository.

wankai123 pushed a change to branch MAL-test
in repository https://gitbox.apache.org/repos/asf/skywalking.git


      at 564ebee42a Address review: fix test state leakage and strengthen ScopeTest assertions

This branch includes the following new commits:

     new 564ebee42a Address review: fix test state leakage and strengthen ScopeTest assertions

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(skywalking) 01/01: Address review: fix test state leakage and strengthen ScopeTest assertions

Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wankai123 pushed a commit to branch MAL-test
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 564ebee42ada9fb4ed583106f1dc9550830598e4
Author: wankai123 <wa...@foxmail.com>
AuthorDate: Tue Aug 4 14:28:47 2026 +0800

    Address review: fix test state leakage and strengthen ScopeTest assertions
    
    - ScopeTest: compare the produced/expected MeterEntity key sets and iterate over
      the expected map so a missing or extra entity fails the test.
    - K8sTagTest: capture and restore the KubernetesServices/KubernetesPods enum
      singletons so the mocked instances do not leak into other tests.
    - DecorateTest: move MeterEntity naming-control setup into @BeforeAll/@AfterAll
      and reset it so the global state is not leaked.
---
 .../oap/meter/analyzer/v2/dsl/DecorateTest.java           | 15 +++++++++++++--
 .../skywalking/oap/meter/analyzer/v2/dsl/K8sTagTest.java  | 15 +++++++++++++++
 .../skywalking/oap/meter/analyzer/v2/dsl/ScopeTest.java   |  8 ++++++--
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/DecorateTest.java b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/DecorateTest.java
index 7c701a35dd..d6eec9b843 100644
--- a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/DecorateTest.java
+++ b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/DecorateTest.java
@@ -22,16 +22,27 @@ import com.google.common.collect.ImmutableMap;
 import org.apache.skywalking.oap.server.core.analysis.meter.MeterEntity;
 import org.apache.skywalking.oap.server.core.config.NamingControl;
 import org.apache.skywalking.oap.server.core.config.group.EndpointNameGrouping;
+import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 import static com.google.common.collect.ImmutableMap.of;
 
 public class DecorateTest {
-    @Test
-    public void testDecorate() {
+    @BeforeAll
+    public static void setup() {
         MeterEntity.setNamingControl(
             new NamingControl(512, 512, 512, new EndpointNameGrouping()));
+    }
+
+    @AfterAll
+    public static void tearDown() {
+        MeterEntity.setNamingControl(null);
+    }
+
+    @Test
+    public void testDecorate() {
         ImmutableMap<String, SampleFamily> input = ImmutableMap.of(
             "http_success_request",
             SampleFamilyBuilder.newBuilder(
diff --git a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/K8sTagTest.java b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/K8sTagTest.java
index 89e3ee06b6..e2726e624f 100644
--- a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/K8sTagTest.java
+++ b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/K8sTagTest.java
@@ -35,6 +35,7 @@ import org.apache.skywalking.library.kubernetes.KubernetesServices;
 import org.apache.skywalking.library.kubernetes.ObjectID;
 import org.apache.skywalking.oap.meter.analyzer.v2.dsl.tagOpt.Retag;
 import org.apache.skywalking.oap.server.core.analysis.IDManager;
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.junit.jupiter.params.ParameterizedTest;
@@ -234,9 +235,16 @@ public class K8sTagTest {
             });
     }
 
+    private KubernetesServices originalServices;
+    private KubernetesPods originalPods;
+
     @SneakyThrows
     @BeforeEach
     public void setup() {
+        // KubernetesServices/KubernetesPods are enum singletons; capture the real INSTANCE so the
+        // mock swap below can be undone in tearDown and does not leak into other tests in this JVM.
+        originalServices = KubernetesServices.INSTANCE;
+        originalPods = KubernetesPods.INSTANCE;
         ReflectUtil.setInternalState(KubernetesServices.class, "INSTANCE",
                                   Mockito.mock(KubernetesServices.class)
         );
@@ -263,6 +271,13 @@ public class K8sTagTest {
         });
     }
 
+    @SneakyThrows
+    @AfterEach
+    public void tearDown() {
+        ReflectUtil.setInternalState(KubernetesServices.class, "INSTANCE", originalServices);
+        ReflectUtil.setInternalState(KubernetesPods.class, "INSTANCE", originalPods);
+    }
+
     @ParameterizedTest(name = "{index}: {0}")
     @MethodSource("data")
     public void test(String name,
diff --git a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/ScopeTest.java b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/ScopeTest.java
index 143df66448..3529e5b521 100644
--- a/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/ScopeTest.java
+++ b/oap-server/analyzer/meter-analyzer/src/test/java/org/apache/skywalking/oap/meter/analyzer/v2/dsl/ScopeTest.java
@@ -37,6 +37,7 @@ import java.util.Map;
 
 import static com.google.common.collect.ImmutableMap.of;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
 
@@ -631,8 +632,11 @@ public class ScopeTest {
         }
         assertTrue(r.isSuccess());
         Map<MeterEntity, Sample[]> meterSamplesR = r.getData().context.getMeterSamples();
-        meterSamplesR.forEach((meterEntity, samples) -> {
-            assertArrayEquals(want.get(meterEntity), samples);
+        // Compare the entity sets first so a missing (or extra) expected entity fails the test,
+        // then iterate over `want` so every expected entity's samples are asserted.
+        assertEquals(want.keySet(), meterSamplesR.keySet());
+        want.forEach((meterEntity, samples) -> {
+            assertArrayEquals(samples, meterSamplesR.get(meterEntity));
         });
     }
 }