internal/atlas: bug fix: fix GC tests

Updates #2897
This commit is contained in:
Hajime Hoshi 2024-01-29 21:01:49 +09:00
parent d2a9e5b1e8
commit f74d66e89a

View File

@ -813,11 +813,17 @@ func TestIteratingImagesToPutOnSourceBackend(t *testing.T) {
func TestGC(t *testing.T) { func TestGC(t *testing.T) {
img := atlas.NewImage(16, 16, atlas.ImageTypeRegular) img := atlas.NewImage(16, 16, atlas.ImageTypeRegular)
img.WritePixels(make([]byte, 4*16*16), image.Rect(0, 0, 16, 16)) img.WritePixels(make([]byte, 4*16*16), image.Rect(0, 0, 16, 16))
c0 := atlas.DeferredFuncCountForTesting()
// Ensure other objects are GCed, as GC appends deferred functions for collected objects.
runtime.GC()
// Get the difference of the number of deferred functions before and after img is GCed.
c := atlas.DeferredFuncCountForTesting()
runtime.KeepAlive(img) runtime.KeepAlive(img)
runtime.GC() runtime.GC()
c1 := atlas.DeferredFuncCountForTesting() diff := atlas.DeferredFuncCountForTesting() - c
if got, want := c1, c0+1; got != want {
if got, want := diff, 1; got != want {
t.Errorf("got: %d, want: %d", got, want) t.Errorf("got: %d, want: %d", got, want)
} }
} }