~eliasnaur/gio-patches

cmd/gogio: don't hang on some e2e test errors v1 PROPOSED

Daniel Martí: 1
 cmd/gogio: don't hang on some e2e test errors

 4 files changed, 25 insertions(+), 10 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9511/mbox | git am -3
Learn more about email & git

[PATCH] cmd/gogio: don't hang on some e2e test errors Export this patch

For example, if the test app fails to start on wayland, we'd block
~forever (ten minutes) waiting for it to render its first frame.

We don't have a good solution right now. But at least we can use a
relatively short timeout, to help out the human who rightfully expects
a result within ten seconds.

While at it, remove a sway "get_seats" command, which was a leftover
from my debugging of what input devices are available when running
headless.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
---
 cmd/gogio/e2e_test.go     | 18 ++++++++++++++++++
 cmd/gogio/js_test.go      |  4 ++--
 cmd/gogio/wayland_test.go |  9 +++------
 cmd/gogio/x11_test.go     |  4 ++--
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/cmd/gogio/e2e_test.go b/cmd/gogio/e2e_test.go
index d16d90f..63a8f59 100644
--- a/cmd/gogio/e2e_test.go
+++ b/cmd/gogio/e2e_test.go
@@ -7,6 +7,7 @@ import (
	"image"
	"image/color"
	"testing"
	"time"
)

var raceEnabled = false
@@ -148,3 +149,20 @@ func wantColor(t *testing.T, img image.Image, x, y int, want color.Color) {
			r_, g_, b_, x, y, r, g, b)
	}
}

func waitForFrame(t *testing.T, frameNotifs <-chan bool) {
	// Unfortunately, there isn't a way to select on a test failing, since
	// testing.T doesn't have anything like a context or a "done" channel.
	//
	// We can't let selects block forever, since the default -test.timeout
	// is ten minutes - far too long for tests that take seconds.
	//
	// For now, a static short timeout is better than nothing. 2s is plenty
	// for our simple test app to render on any device.

	select {
	case <-frameNotifs:
	case <-time.After(2 * time.Second):
		t.Fatalf("timed out waiting for a frame to be ready")
	}
}
diff --git a/cmd/gogio/js_test.go b/cmd/gogio/js_test.go
index 0929aa0..3b7df63 100644
--- a/cmd/gogio/js_test.go
+++ b/cmd/gogio/js_test.go
@@ -129,7 +129,7 @@ func (d *JSTestDriver) Start(t_ *testing.T, path string, width, height int) {
	}

	// Wait for the gio app to render.
	<-d.frameNotifs
	waitForFrame(d.t, d.frameNotifs)
}

func (d *JSTestDriver) Screenshot() image.Image {
@@ -154,5 +154,5 @@ func (d *JSTestDriver) Click(x, y int) {
	}

	// Wait for the gio app to render after this click.
	<-d.frameNotifs
	waitForFrame(d.t, d.frameNotifs)
}
diff --git a/cmd/gogio/wayland_test.go b/cmd/gogio/wayland_test.go
index c3f0672..a57f8a8 100644
--- a/cmd/gogio/wayland_test.go
+++ b/cmd/gogio/wayland_test.go
@@ -185,7 +185,7 @@ func (d *WaylandTestDriver) Start(t_ *testing.T, path string, width, height int)
	}

	// Wait for the gio app to render.
	<-d.frameNotifs
	waitForFrame(d.t, d.frameNotifs)
}

func (d *WaylandTestDriver) Screenshot() image.Image {
@@ -204,9 +204,7 @@ func (d *WaylandTestDriver) Screenshot() image.Image {
}

func (d *WaylandTestDriver) swaymsg(args ...interface{}) {
	strs := []string{
		"--socket", d.socket,
	}
	strs := []string{"--socket", d.socket}
	for _, arg := range args {
		strs = append(strs, fmt.Sprint(arg))
	}
@@ -218,11 +216,10 @@ func (d *WaylandTestDriver) swaymsg(args ...interface{}) {
}

func (d *WaylandTestDriver) Click(x, y int) {
	d.swaymsg("-t", "get_seats")
	d.swaymsg("seat", "-", "cursor", "set", x, y)
	d.swaymsg("seat", "-", "cursor", "press", "button1")
	d.swaymsg("seat", "-", "cursor", "release", "button1")

	// Wait for the gio app to render after this click.
	<-d.frameNotifs
	waitForFrame(d.t, d.frameNotifs)
}
diff --git a/cmd/gogio/x11_test.go b/cmd/gogio/x11_test.go
index f642b29..e23e655 100644
--- a/cmd/gogio/x11_test.go
+++ b/cmd/gogio/x11_test.go
@@ -164,7 +164,7 @@ func (d *X11TestDriver) Start(t_ *testing.T, path string, width, height int) {
	}

	// Wait for the gio app to render.
	<-d.frameNotifs
	waitForFrame(d.t, d.frameNotifs)
}

func (d *X11TestDriver) Screenshot() image.Image {
@@ -200,5 +200,5 @@ func (d *X11TestDriver) Click(x, y int) {
	d.xdotool("click", "1")

	// Wait for the gio app to render after this click.
	<-d.frameNotifs
	waitForFrame(d.t, d.frameNotifs)
}
-- 
2.24.1
Thanks, applied.
View this thread in the archives