1
0
mirror of https://github.com/golang/go synced 2024-11-15 05:40:32 -07:00

expvar: add the missing deletion step for keys

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.
This commit is contained in:
apocelipes 2024-04-04 14:34:12 +08:00
parent 8121604559
commit a351ce095b
2 changed files with 7 additions and 0 deletions

View 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)
}
}

View 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 {