mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
internal/atlas: bug fix: test flakiness due to GC
This commit is contained in:
parent
820c996329
commit
24256af624
@ -19,6 +19,7 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
@ -821,8 +822,17 @@ func TestGC(t *testing.T) {
|
|||||||
c := atlas.DeferredFuncCountForTesting()
|
c := atlas.DeferredFuncCountForTesting()
|
||||||
runtime.KeepAlive(img)
|
runtime.KeepAlive(img)
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
diff := atlas.DeferredFuncCountForTesting() - c
|
|
||||||
|
|
||||||
|
// In theory, a finalizer might be called a little later. Try a few times.
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
diff := atlas.DeferredFuncCountForTesting() - c
|
||||||
|
if diff == 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
diff := atlas.DeferredFuncCountForTesting() - c
|
||||||
if got, want := diff, 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)
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
@ -98,8 +99,17 @@ func TestGCShader(t *testing.T) {
|
|||||||
c := atlas.DeferredFuncCountForTesting()
|
c := atlas.DeferredFuncCountForTesting()
|
||||||
runtime.KeepAlive(s)
|
runtime.KeepAlive(s)
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
diff := atlas.DeferredFuncCountForTesting() - c
|
|
||||||
|
|
||||||
|
// In theory, a finalizer might be called a little later. Try a few times.
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
diff := atlas.DeferredFuncCountForTesting() - c
|
||||||
|
if diff == 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
diff := atlas.DeferredFuncCountForTesting() - c
|
||||||
if got, want := diff, 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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user