cmd/gogio: remove sleeps in x11 e2e test

We can instead synchronize with the gio app via stdout. We need three
states, since we need to first invalidate a frame and then print when
the next frame is drawn.

This is not happening on the JS test yet, because stdout printing
crashes in that case. See the comment.

This change should make the X11 test a bit faster on fast machines,
while making it more stable in small or headless machines like CI.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
Daniel Martí
2019-11-02 11:45:57 +00:00
committed by Elias Naur
parent 2a9361db65
commit 97d13922dd
3 changed files with 60 additions and 11 deletions
+32
View File
@@ -4,9 +4,11 @@
package main
import (
"fmt"
"image"
"image/color"
"log"
"runtime"
"gioui.org/app"
"gioui.org/f32"
@@ -26,6 +28,18 @@ func main() {
app.Main()
}
type notifyFrame int
const (
notifyNone notifyFrame = iota
notifyInvalidate
notifyPrint
)
// notify keeps track of whether we want to print to stdout to notify the user
// when a frame is ready. Initially we want to notify about the first frame.
var notify = notifyInvalidate
func loop(w *app.Window) error {
topLeft := quarterWidget{
color: color.RGBA{R: 0xde, G: 0xad, B: 0xbe, A: 0xff},
@@ -67,6 +81,22 @@ func loop(w *app.Window) error {
rows.Layout(gtx, r1, r2)
e.Frame(gtx.Ops)
if runtime.GOOS == "js" {
// TODO(mvdan): Unfortunately, printing to
// stdout crashes the js/wasm port. Use the
// prints once the issue is fixed:
// https://github.com/golang/go/issues/35256
break
}
switch notify {
case notifyInvalidate:
notify = notifyPrint
w.Invalidate()
case notifyPrint:
notify = notifyNone
fmt.Println("frame ready")
}
}
}
}
@@ -100,6 +130,8 @@ func (w *quarterWidget) Layout(gtx *layout.Context) {
for _, e := range gtx.Events(w) {
if e, ok := e.(pointer.Event); ok && e.Type == pointer.Press {
w.clicked = !w.clicked
// notify when we're done updating the frame.
notify = notifyInvalidate
}
}
}