mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 23:55:39 +00:00
9bbeb92b61
We were using 'go run . <args>' before, which works fine, but does mean re-linking a new binary and throwing it away at each invocation. Given that the end-to-end tests don't do all that much work besides building the tiny red.go app, this amount of extra work was noticeable. We can obtain statistics for the JS sub-test, which used 'go run', via the perflock and benchcmd tools: $ go test -c $ perflock -governorp% benchcmd EndToEnd/JS ./gogio.test -test.run=EndToEnd/JS After capturing those numbers before and after the change, we can then compare them with benchstat. The CPU cost of the subtest is halved: name old time/op new time/op delta EndToEnd/JS 1.42s ± 2% 1.07s ± 3% -25.04% (p=0.008 n=5+5) name old user-time/op new user-time/op delta EndToEnd/JS 1.46s ± 3% 0.75s ± 5% -48.34% (p=0.008 n=5+5) name old sys-time/op new sys-time/op delta EndToEnd/JS 366ms ±13% 224ms ± 7% -38.79% (p=0.008 n=5+5) An alternative here would have been to refactor main.go to allow being called directly. However, that would have required a non-trivial refactor, since flag parsing is done via globals. Given that the TestMain method is asy and keeps the main function simple, we've decided to avoid a refactor. While at it, remove the sleep in the Android driver to wait for the app to come up on screen. Since we retry screenshots now, we no longer need a static sleep. On average, we still need one retry for the initial screenshot, but that's just 100ms versus the old 500ms. The maximum wait time is also 2s here, which should scale better for slower devices. Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
if os.Getenv("RUN_GOGIO") != "" {
|
|
// Allow the end-to-end tests to call the gogio tool without
|
|
// having to build it from scratch, nor having to refactor the
|
|
// main function to avoid using global variables.
|
|
main()
|
|
os.Exit(0) // main already exits, but just in case.
|
|
}
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
type expval struct {
|
|
in, out string
|
|
}
|
|
|
|
func TestAppID(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []expval{
|
|
{"example", "localhost.example"},
|
|
{"example.com", "com.example"},
|
|
{"www.example.com", "com.example.www"},
|
|
{"examplecom/app", "examplecom.app"},
|
|
{"example.com/app", "com.example.app"},
|
|
{"www.example.com/app", "com.example.www.app"},
|
|
{"www.en.example.com/app", "com.example.en.www.app"},
|
|
{"example.com/dir/app", "com.example.app"},
|
|
{"example.com/dir.ext/app", "com.example.app"},
|
|
{"example.com/dir/app.ext", "com.example.app.ext"},
|
|
{"example-com.net/dir/app", "net.example_com.app"},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
got := appIDFromPackage(test.in)
|
|
if exp := test.out; got != exp {
|
|
t.Errorf("(%d): expected '%s', got '%s'", i, exp, got)
|
|
}
|
|
}
|
|
}
|