Files
crush/internal/ui/image/image_test.go
M1xAandGitHub fb9eb927de fix(ui): clear image cache when FilePicker closes to prevent unbounded memory growth (#2158)
* fix(ui): clear image cache when FilePicker closes to prevent unbounded memory growth

* fix(ui): only reset image cache on FilePicker close, not on new session

* fix(ui): reset image cache after Dialog close

* fix(ui): rename image.Reset to image.ResetCache for clarity
2026-02-09 09:44:43 +03:00

47 lines
816 B
Go

package image
import (
"image"
"testing"
"github.com/stretchr/testify/require"
)
func TestResetCache(t *testing.T) {
t.Parallel()
cachedMutex.Lock()
cachedImages[imageKey{id: "a", cols: 10, rows: 10}] = cachedImage{
img: image.NewRGBA(image.Rect(0, 0, 1, 1)),
cols: 10,
rows: 10,
}
cachedImages[imageKey{id: "b", cols: 20, rows: 20}] = cachedImage{
img: image.NewRGBA(image.Rect(0, 0, 1, 1)),
cols: 20,
rows: 20,
}
cachedMutex.Unlock()
ResetCache()
cachedMutex.RLock()
length := len(cachedImages)
cachedMutex.RUnlock()
require.Equal(t, 0, length)
}
func TestResetIdempotent(t *testing.T) {
t.Parallel()
// Calling Reset on an empty cache should not panic.
ResetCache()
cachedMutex.RLock()
length := len(cachedImages)
cachedMutex.RUnlock()
require.Equal(t, 0, length)
}