Skip to content

Commit

Permalink
Merge pull request #1614 from toaster/bugfix/animation_tests
Browse files Browse the repository at this point in the history
Bugfix/animation tests
  • Loading branch information
toaster committed Nov 27, 2020
2 parents 9dfe949 + a1ef57c commit 7998b3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
28 changes: 18 additions & 10 deletions internal/animation/animation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,39 @@ import (
)

func TestGLDriver_StartAnimation(t *testing.T) {
done := make(chan float32)
run := &Runner{}
ticks := 0
a := &fyne.Animation{
Duration: time.Millisecond * 100,
Tick: func(done float32) {
ticks++
Tick: func(d float32) {
done <- d
}}

run.Start(a)
time.Sleep(time.Millisecond * 20)
assert.Greater(t, ticks, 0)
select {
case d := <-done:
assert.Greater(t, d, float32(0))
case <-time.After(100 * time.Millisecond):
t.Error("animation was not ticked")
}
}

func TestGLDriver_StopAnimation(t *testing.T) {
done := make(chan float32)
run := &Runner{}
ticks := 0
a := &fyne.Animation{
Duration: time.Second * 10,
Tick: func(done float32) {
ticks++
Tick: func(d float32) {
done <- d
}}

run.Start(a)
time.Sleep(time.Millisecond * 20)
select {
case d := <-done:
assert.Greater(t, d, float32(0))
case <-time.After(100 * time.Millisecond):
t.Error("animation was not ticked")
}
run.Stop(a)
assert.Greater(t, ticks, 0)
assert.Zero(t, len(run.animations))
}
4 changes: 2 additions & 2 deletions internal/animation/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func (r *Runner) runAnimations() {
draw := time.NewTicker(time.Second / 60)

go func() {
done := false
for !done {
for done := false; !done; {
<-draw.C
r.animationMutex.Lock()
oldList := r.animations
Expand All @@ -61,6 +60,7 @@ func (r *Runner) runAnimations() {
done = len(r.animations) == 0
r.animationMutex.Unlock()
}
draw.Stop()
}()
}

Expand Down

0 comments on commit 7998b3c

Please sign in to comment.