test: Use flock to make tests exclusive

Fixes #575
This commit is contained in:
Hajime Hoshi 2018-04-06 03:54:10 +09:00
parent e77eb9f80f
commit 9902497e3d
5 changed files with 59 additions and 4 deletions

View File

@ -29,9 +29,13 @@ import (
"github.com/hajimehoshi/ebiten/ebitenutil"
"github.com/hajimehoshi/ebiten/examples/resources/images"
emath "github.com/hajimehoshi/ebiten/internal/math"
"github.com/hajimehoshi/ebiten/internal/testflock"
)
func TestMain(m *testing.M) {
testflock.Lock()
defer testflock.Unlock()
code := 0
// Run an Ebiten process so that (*Image).At is available.
regularTermination := errors.New("regular termination")

View File

@ -26,9 +26,13 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/opengl"
. "github.com/hajimehoshi/ebiten/internal/restorable"
"github.com/hajimehoshi/ebiten/internal/testflock"
)
func TestMain(m *testing.M) {
testflock.Lock()
defer testflock.Unlock()
EnableRestoringForTesting()
code := 0
regularTermination := errors.New("regular termination")

View File

@ -25,9 +25,13 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/opengl"
. "github.com/hajimehoshi/ebiten/internal/shareable"
"github.com/hajimehoshi/ebiten/internal/testflock"
)
func TestMain(m *testing.M) {
testflock.Lock()
defer testflock.Unlock()
code := 0
regularTermination := errors.New("regular termination")
f := func(screen *ebiten.Image) error {
@ -42,8 +46,7 @@ func TestMain(m *testing.M) {
const bigSize = 2049
// Temporary disabled per #575.
func Disabled_TestEnsureNotShared(t *testing.T) {
func TestEnsureNotShared(t *testing.T) {
// Create img1 and img2 with this size so that the next images are allocated
// with non-upper-left location.
img1 := NewImage(bigSize, 100)

View File

@ -0,0 +1,41 @@
// Copyright 2018 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package testflock provides a lock for testing.
//
// There is a CI service like TravisCI where multiple OpenGL processes
// don't work well at the same time, and tests with an OpenGL main routine
// should be protected by a file lock (#575).
package testflock
import (
"os"
"path/filepath"
"github.com/theckman/go-flock"
)
var theLock = flock.NewFlock(filepath.Join(os.TempDir(), "ebitentest"))
func Lock() {
if err := theLock.Lock(); err != nil {
panic(err)
}
}
func Unlock() {
if err := theLock.Unlock(); err != nil {
panic(err)
}
}

View File

@ -21,12 +21,15 @@ import (
"testing"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/go-mplusbitmap"
"github.com/hajimehoshi/ebiten/internal/testflock"
. "github.com/hajimehoshi/ebiten/text"
"github.com/hajimehoshi/go-mplusbitmap"
)
func TestMain(m *testing.M) {
testflock.Lock()
defer testflock.Unlock()
code := 0
// Run an Ebiten process so that (*Image).At is available.
regularTermination := errors.New("regular termination")