Skip to content

Commit

Permalink
add TestClose
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed Mar 27, 2024
1 parent 748fd49 commit 3f2cbcd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,25 @@ func TestKeys(t *testing.T) {
}
}
}

func TestClose(t *testing.T) {
db := New[string, string]()
db.Set("1", "one")
db.Set("2", "two")
db.SetWithTimeout("3", "three", time.Second)

db.Close()

select {
case _, ok := <-db.stopCh:
if ok {
t.Errorf("Close: expiration goroutine did not stop as expected")
}
default:
t.Errorf("Close: expiration goroutine did not stop as expected")
}

if len(db.m) != 0 {
t.Errorf("Close: database map is not cleaned up")
}
}

0 comments on commit 3f2cbcd

Please sign in to comment.