File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,26 @@ func TestDeleteExpired(t *testing.T) {
123123 t .Errorf ("want2 %d items but got2 %d" , want2 , got2 )
124124 }
125125 })
126+
127+ t .Run ("issue #51" , func (t * testing.T ) {
128+ defer restore ()
129+ c := New [string , int ]()
130+
131+ c .Set ("1" , 10 , WithExpiration (10 * time .Millisecond ))
132+ c .Set ("2" , 20 , WithExpiration (20 * time .Millisecond ))
133+ c .Set ("1" , 30 , WithExpiration (100 * time .Millisecond )) // expected do not expired key "1"
134+
135+ nowFunc = func () time.Time {
136+ return now .Add (30 * time .Millisecond ).Add (time .Millisecond )
137+ }
138+
139+ c .DeleteExpired ()
140+
141+ got := c .Len ()
142+ if want := 1 ; want != got {
143+ t .Errorf ("want %d items but got %d" , want , got )
144+ }
145+ })
126146}
127147
128148func max (x , y int ) int {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ func newExpirationManager[K comparable]() *expirationManager[K] {
2121
2222func (m * expirationManager [K ]) update (key K , expiration time.Time ) {
2323 if e , ok := m .mapping [key ]; ok {
24+ e .expiration = expiration
2425 heap .Fix (& m .queue , e .index )
2526 } else {
2627 v := & expirationKey [K ]{
You can’t perform that action at this time.
0 commit comments