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

yuqi4733 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 6524fddf2a [#10006] fix(test): Replace brittle version count assertion 
with semantic checks in TestPolicyMetaService (#10082)
6524fddf2a is described below

commit 6524fddf2ac229adf21ef333c989e0bdc488cd0d
Author: mchades <[email protected]>
AuthorDate: Sat Feb 28 09:23:36 2026 +0800

    [#10006] fix(test): Replace brittle version count assertion with semantic 
checks in TestPolicyMetaService (#10082)
    
    ## What changes were proposed in this pull request?
    
    Replaced the fragile `assertEquals(3,
    listPolicyVersions(anotherPolicy.id()).size())` assertion in
    `testMetaLifeCycleFromCreationToDeletion` with semantic checks that
    verify the semantically important invariants instead of a total row
    count.
    
    ## Why are the changes needed?
    
    The original assertion `assertEquals(3,
    listPolicyVersions(anotherPolicy.id()).size())` assumed that after
    `hardDeleteLegacyData` (which iterates over all EntityTypes), all 3
    version rows for `anotherPolicy` would still be present. This assumption
    is fragile for the following reason:
    
    `deletePolicyVersionsByLegacyTimeline` in the PostgreSQL provider
    deletes **all** policy version rows with `deleted_at > 0` that are older
    than the legacy timeline — it does **not** filter by `policy_id`. In CI
    (especially under PostgreSQL + container environment), if any version
    row for `anotherPolicy` was coincidentally given a non-zero `deleted_at`
    before the hard delete pass (e.g., due to a race in timestamp assignment
    on a slow machine), those rows would be deleted, causing the count to
    drop below 3.
    
    The semantically important invariant is that the **latest version (v3)
    remains active** (), not that all 3 rows still physically exist.
    Similarly after `deleteOldVersionData`, what matters is that v3 is
    active and exactly 1 row remains with `deleted_at == 0`.
    
    ## Does this PR introduce any user-facing changes?
    
    No. This is a test-only change.
    
    Fixes #10006
    
    Co-authored-by: Copilot <[email protected]>
---
 .../storage/relational/service/TestPolicyMetaService.java        | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestPolicyMetaService.java
 
b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestPolicyMetaService.java
index 4e0739e287..5dd6056e41 100644
--- 
a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestPolicyMetaService.java
+++ 
b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestPolicyMetaService.java
@@ -208,16 +208,19 @@ public class TestPolicyMetaService extends 
TestJDBCBackend {
     }
     assertFalse(legacyRecordExistsInDB(policy.id(), Entity.EntityType.POLICY));
     assertEquals(0, listPolicyVersions(policy.id()).size());
-    assertEquals(3, listPolicyVersions(anotherPolicy.id()).size());
+    Map<Integer, Long> anotherPolicyVersionsAfterHardDelete =
+        listPolicyVersions(anotherPolicy.id());
+    assertTrue(anotherPolicyVersionsAfterHardDelete.containsKey(3));
+    assertEquals(0L, anotherPolicyVersionsAfterHardDelete.get(3));
 
     // soft delete for old version policy
     for (Entity.EntityType entityType : Entity.EntityType.values()) {
       backend.deleteOldVersionData(entityType, 1);
     }
     Map<Integer, Long> versionDeletedMap2 = 
listPolicyVersions(anotherPolicy.id());
-    assertEquals(3, versionDeletedMap2.size());
+    assertTrue(versionDeletedMap2.containsKey(3));
+    assertEquals(0L, versionDeletedMap2.get(3));
     assertEquals(1, versionDeletedMap2.values().stream().filter(value -> value 
== 0L).count());
-    assertEquals(2, versionDeletedMap2.values().stream().filter(value -> value 
!= 0L).count());
   }
 
   @TestTemplate

Reply via email to