mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
parent
cc5174f104
commit
4701a61e4b
@ -19,6 +19,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
@ -307,18 +308,27 @@ func TestWritePixelsAndModifyBeforeMain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isImageGCed bool
|
var imageGCedCh = make(chan struct{})
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
img := buffered.NewImage(1, 1, atlas.ImageTypeRegular)
|
img := buffered.NewImage(1, 1, atlas.ImageTypeRegular)
|
||||||
runtime.SetFinalizer(img, func(*buffered.Image) {
|
runtime.SetFinalizer(img, func(*buffered.Image) {
|
||||||
isImageGCed = true
|
close(imageGCedCh)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGC(t *testing.T) {
|
func TestGC(t *testing.T) {
|
||||||
|
t.Skip("flaky (especially on GitHub Actions)")
|
||||||
|
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
if !isImageGCed {
|
runtime.GC()
|
||||||
|
|
||||||
|
// A finalizer should be called eventually, but this might not be immediate.
|
||||||
|
// Set a time out.
|
||||||
|
select {
|
||||||
|
case <-imageGCedCh:
|
||||||
|
return
|
||||||
|
case <-time.After(time.Second):
|
||||||
t.Error("an image in init() must be GCed but not")
|
t.Error("an image in init() must be GCed but not")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user