]> Cypherpunks repositories - gostls13.git/commitdiff
expvar: add the missing deletion step for keys
authorapocelipes <seve3r@outlook.com>
Thu, 4 Apr 2024 06:59:50 +0000 (06:59 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 4 Apr 2024 14:46:19 +0000 (14:46 +0000)
In CL575777 I forgot to remove the key from the "sync.Map".
This did not cause the test to fail due to the lack of an associated
testcase. Now delete the key correctly and add the testcase.

Change-Id: I26f770966a828caa02f1766675756b67894dc195
GitHub-Last-Rev: a351ce095b5256fd1351d71f09ba38fdcdfce3d9
GitHub-Pull-Request: golang/go#66675
Reviewed-on: https://go-review.googlesource.com/c/go/+/576395
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: qiu laidongfeng2 <2645477756@qq.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
src/expvar/expvar.go
src/expvar/expvar_test.go

index a30963c5a8aac8f9d20b34c215fbc953cc63bfe2..ffe35d62f917a7127f57af8a64253cf064782b82 100644 (file)
@@ -249,6 +249,7 @@ func (v *Map) Delete(key string) {
        i, found := slices.BinarySearch(v.keys, key)
        if found {
                v.keys = slices.Delete(v.keys, i, i+1)
+               v.m.Delete(key)
        }
 }
 
index b827c4d621b93966b7a959bfa70f5307963d3480..def84179532e4e3530ac5ffcaa74e4fe164c0e70 100644 (file)
@@ -199,6 +199,9 @@ func TestMapDelete(t *testing.T) {
        }
 
        colors.Delete("red")
+       if v := colors.Get("red"); v != nil {
+               t.Errorf("removed red, Get should return nil; got %v", v)
+       }
        n = 0
        colors.Do(func(KeyValue) { n++ })
        if n != 1 {
@@ -214,6 +217,9 @@ func TestMapDelete(t *testing.T) {
 
        colors.Delete("blue")
        colors.Delete("blue")
+       if v := colors.Get("blue"); v != nil {
+               t.Errorf("removed blue, Get should return nil; got %v", v)
+       }
        n = 0
        colors.Do(func(KeyValue) { n++ })
        if n != 0 {