@@ -40,8 +40,8 @@ func TestCache_Basic(t *testing.T) {
4040func TestCache_WithTTL (t * testing.T ) {
4141 cache := New [string , string ]()
4242
43- // Set with short TTL
44- cache .SetTTL ("temp" , "value" , 50 * time .Millisecond )
43+ // Set with short TTL (minimum 1 second granularity)
44+ cache .SetTTL ("temp" , "value" , 1 * time .Second )
4545
4646 // Should be available immediately
4747 val , found := cache .Get ("temp" )
@@ -50,7 +50,7 @@ func TestCache_WithTTL(t *testing.T) {
5050 }
5151
5252 // Wait for expiration
53- time .Sleep (100 * time .Millisecond )
53+ time .Sleep (2 * time .Second )
5454
5555 // Should be expired
5656 _ , found = cache .Get ("temp" )
@@ -60,7 +60,7 @@ func TestCache_WithTTL(t *testing.T) {
6060}
6161
6262func TestCache_DefaultTTL (t * testing.T ) {
63- cache := New [string , int ](TTL (50 * time .Millisecond ))
63+ cache := New [string , int ](TTL (1 * time .Second ))
6464
6565 // Set without explicit TTL (ttl=0 uses default)
6666 cache .Set ("key" , 100 )
@@ -72,7 +72,7 @@ func TestCache_DefaultTTL(t *testing.T) {
7272 }
7373
7474 // Wait for default TTL expiration
75- time .Sleep (100 * time .Millisecond )
75+ time .Sleep (2 * time .Second )
7676
7777 // Should be expired
7878 _ , found = cache .Get ("key" )
@@ -236,11 +236,11 @@ func TestCache_EvictFromMain(t *testing.T) {
236236func TestCache_GetExpired (t * testing.T ) {
237237 cache := New [string , int ]()
238238
239- // Set with very short TTL
240- cache .SetTTL ("key1" , 42 , 1 * time .Millisecond )
239+ // Set with short TTL (1 second granularity)
240+ cache .SetTTL ("key1" , 42 , 1 * time .Second )
241241
242242 // Wait for expiration
243- time .Sleep (10 * time .Millisecond )
243+ time .Sleep (2 * time .Second )
244244
245245 // Get should return not found
246246 _ , found := cache .Get ("key1" )
@@ -368,8 +368,8 @@ func TestCache_SetTTL(t *testing.T) {
368368 t .Error ("default-ttl should be found" )
369369 }
370370
371- // SetTTL uses explicit short TTL
372- cache .SetTTL ("short-ttl" , 2 , 50 * time .Millisecond )
371+ // SetTTL uses explicit short TTL (1 second granularity)
372+ cache .SetTTL ("short-ttl" , 2 , 1 * time .Second )
373373 if _ , found := cache .Get ("short-ttl" ); ! found {
374374 t .Error ("short-ttl should be found immediately" )
375375 }
@@ -387,7 +387,7 @@ func TestCache_SetTTL(t *testing.T) {
387387 }
388388
389389 // Wait for short TTL to expire
390- time .Sleep (100 * time .Millisecond )
390+ time .Sleep (2 * time .Second )
391391
392392 // short-ttl should be expired, others should still exist
393393 if _ , found := cache .Get ("short-ttl" ); found {
@@ -411,7 +411,7 @@ func TestCache_Set_NoDefaultTTL(t *testing.T) {
411411 cache .Set ("no-expiry" , 42 )
412412
413413 // Wait a bit
414- time .Sleep (50 * time .Millisecond )
414+ time .Sleep (100 * time .Millisecond )
415415
416416 // Should still exist
417417 val , found := cache .Get ("no-expiry" )
@@ -531,8 +531,8 @@ func TestCache_GetSet_WithTTL(t *testing.T) {
531531 return loaderCalls * 10 , nil
532532 }
533533
534- // First call with short TTL
535- val , err := cache .GetSetTTL ("key1" , loader , 50 * time .Millisecond )
534+ // First call with short TTL (1 second granularity)
535+ val , err := cache .GetSetTTL ("key1" , loader , 1 * time .Second )
536536 if err != nil {
537537 t .Fatalf ("GetSet error: %v" , err )
538538 }
@@ -541,10 +541,10 @@ func TestCache_GetSet_WithTTL(t *testing.T) {
541541 }
542542
543543 // Wait for TTL to expire
544- time .Sleep (100 * time .Millisecond )
544+ time .Sleep (2 * time .Second )
545545
546546 // Second call - should call loader again (cache expired)
547- val , err = cache .GetSetTTL ("key1" , loader , 50 * time .Millisecond )
547+ val , err = cache .GetSetTTL ("key1" , loader , 1 * time .Second )
548548 if err != nil {
549549 t .Fatalf ("GetSet error: %v" , err )
550550 }
0 commit comments