add cleanup task to widget pool

This commit is contained in:
Drew Weymouth
2023-07-11 16:38:50 -07:00
parent f75a5e27a5
commit 2df0514468
3 changed files with 83 additions and 21 deletions
+24
View File
@@ -0,0 +1,24 @@
package util
import (
"testing"
"time"
)
func Test_WidgetPool_CleanupExpiredItems(t *testing.T) {
now := time.Now()
threeMinAgo := now.Add(-3 * time.Minute)
w := &WidgetPool{
pools: [][]pooledWidget{
{
{releasedAt: threeMinAgo.UnixMilli()},
{releasedAt: threeMinAgo.UnixMilli()},
{releasedAt: threeMinAgo.UnixMilli()},
},
},
}
w.cleanUpExpiredItems()
if l := len(w.pools[0]); l != 1 {
t.Errorf("Expected one widget in pool after cleanup, got %d", l)
}
}