mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
@ -821,8 +822,17 @@ func TestGC(t *testing.T) {
|
||||
c := atlas.DeferredFuncCountForTesting()
|
||||
runtime.KeepAlive(img)
|
||||
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 {
|
||||
t.Errorf("got: %d, want: %d", got, want)
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"image/color"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
@ -98,8 +99,17 @@ func TestGCShader(t *testing.T) {
|
||||
c := atlas.DeferredFuncCountForTesting()
|
||||
runtime.KeepAlive(s)
|
||||
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 {
|
||||
t.Errorf("got: %d, want: %d", got, want)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user