Skip to content

Commit

Permalink
Optimize the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmlkzdh committed Oct 20, 2024
1 parent 2a756eb commit fe5c29d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions timedmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestTimedMapGetNonExistentKey(t *testing.T) {
func TestTimedMapGetExpiredKey(t *testing.T) {
tm := New[string, int]()
tm.Put("key", 19, 100*time.Millisecond)
time.Sleep(time.Second)
time.Sleep(200 * time.Millisecond)
_, ok := tm.Get("key")
if ok {
t.Errorf("expected ok to be false")
Expand Down Expand Up @@ -96,9 +96,9 @@ func TestTimedMapClear(t *testing.T) {

func TestTimedMapExpiration(t *testing.T) {
tm := New[string, int]()
tm.Put("key1", 19, 3*time.Second)
tm.Put("key2", 23, time.Second)
time.Sleep(2 * time.Second)
tm.Put("key1", 19, 300*time.Millisecond)
tm.Put("key2", 23, 100*time.Millisecond)
time.Sleep(200 * time.Millisecond)
_, ok := tm.Get("key1")
if !ok {
t.Errorf("expected key1 to still be present")
Expand All @@ -110,9 +110,9 @@ func TestTimedMapExpiration(t *testing.T) {
}

func TestTimedMapCleanup(t *testing.T) {
tm := NewWithCleanupInterval[string, int](2 * time.Second)
tm.Put("key", 19, time.Second)
time.Sleep(3 * time.Second)
tm := NewWithCleanupInterval[string, int](200 * time.Millisecond)
tm.Put("key", 19, 100*time.Millisecond)
time.Sleep(300 * time.Millisecond)
_, ok := tm.Get("key")
if ok {
t.Errorf("expected key to be cleaned up and removed")
Expand Down

0 comments on commit fe5c29d

Please sign in to comment.