From 39c396a9793d6a974a1121eda2a8dc225d234766 Mon Sep 17 00:00:00 2001 From: coanor Date: Sun, 28 Sep 2025 17:11:57 +0000 Subject: [PATCH] add test case on kvs-delete-and-then-check-again --- point/check.go | 8 +++++++- point/check_test.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/point/check.go b/point/check.go index 0eeed6d1..c598eebc 100644 --- a/point/check.go +++ b/point/check.go @@ -7,6 +7,7 @@ package point import ( "fmt" + "log" "math" "reflect" "strings" @@ -77,17 +78,22 @@ func (c *checker) checkKVs(kvs KVs) KVs { // check each kv valid idx := 0 - for _, kv := range kvs { + for i, kv := range kvs { if x, ok := c.checkKV(kv, kvs); ok { + log.Printf("set %d kv to %d", i, idx) kvs[idx] = x idx++ } else if defaultPTPool != nil { // When point-pool enabled, on drop f, we should put-back to pool. defaultPTPool.PutKV(x) + } else { + log.Printf("kv at %d removed", i) } } + log.Printf("trim at %d", idx) for j := idx; j < len(kvs); j++ { // remove deleted elems + log.Printf("set %d kv to nil", j) kvs[j] = nil } diff --git a/point/check_test.go b/point/check_test.go index 31e335e9..4388abc0 100644 --- a/point/check_test.go +++ b/point/check_test.go @@ -489,6 +489,26 @@ func TestCheckFields(t *T.T) { } } +func TestCheckAfterDelete(t *T.T) { + t.Run(`basic`, func(t *T.T) { + cfg := GetCfg() + defer PutCfg(cfg) + + WithMaxFieldValLen(1)(cfg) + WithDisabledKeys(NewKey("f3", 0), NewKey("f5", 0))(cfg) + + c := checker{cfg: cfg} + var kvs KVs + + kvs1 := kvs.Add("f1", "1").Add("f2", 2).Add("f3", "333").Add("f4", 3.14).Add("f5", 1.414).Add("f6", "foo") + kvs2 := c.checkKVs(kvs1) + t.Logf("%s", kvs2.Pretty()) + t.Logf("%s", kvs1.Pretty()) + + c.checkKVs(kvs1) + }) +} + func TestAdjustKV(t *T.T) { cases := []struct { name, x, y string