treewide: parallel tests
All checks were successful
Test / Create distribution (push) Successful in 25s
Test / Hakurei (push) Successful in 44s
Test / Sandbox (push) Successful in 41s
Test / Hakurei (race detector) (push) Successful in 44s
Test / Sandbox (race detector) (push) Successful in 41s
Test / Hpkg (push) Successful in 41s
Test / Flake checks (push) Successful in 1m24s

Most tests already had no global state, however parallel was never enabled. This change enables it for all applicable tests.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-10-13 04:38:48 +09:00
parent a14b6535a6
commit 7638a44fa6
78 changed files with 515 additions and 133 deletions

View File

@@ -11,6 +11,8 @@ import (
)
func TestACLUpdateOp(t *testing.T) {
t.Parallel()
checkOpBehaviour(t, []opBehaviourTestCase{
{"apply aclUpdate", 0xdeadbeef, 0xff,
&aclUpdateOp{Process, "/proc/nonexistent", []acl.Perm{acl.Read, acl.Write, acl.Execute}}, []stub.Call{

View File

@@ -5,6 +5,8 @@ import (
)
func TestUnescapeValue(t *testing.T) {
t.Parallel()
testCases := []struct {
value string
want string
@@ -45,6 +47,8 @@ func TestUnescapeValue(t *testing.T) {
for _, tc := range testCases {
t.Run("unescape "+tc.value, func(t *testing.T) {
t.Parallel()
if got, errno := unescapeValue([]byte(tc.value)); errno != tc.wantErr {
t.Errorf("unescapeValue() errno = %v, wantErr %v", errno, tc.wantErr)
} else if tc.wantErr == errSuccess && string(got) != tc.want {

View File

@@ -9,6 +9,8 @@ import (
)
func TestParse(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
addr string
@@ -109,6 +111,8 @@ func TestParse(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
if got, err := dbus.Parse([]byte(tc.addr)); !errors.Is(err, tc.wantErr) {
t.Errorf("Parse() error = %v, wantErr %v", err, tc.wantErr)
} else if tc.wantErr == nil && !reflect.DeepEqual(got, tc.want) {

View File

@@ -11,6 +11,8 @@ import (
)
func TestConfigArgs(t *testing.T) {
t.Parallel()
for _, tc := range testCasesExt {
if tc.wantErr {
// args does not check for nulls
@@ -18,6 +20,8 @@ func TestConfigArgs(t *testing.T) {
}
t.Run("build arguments for "+tc.id, func(t *testing.T) {
t.Parallel()
if got := dbus.Args(tc.c, tc.bus); !slices.Equal(got, tc.want) {
t.Errorf("Args: %v, want %v", got, tc.want)
}
@@ -26,6 +30,7 @@ func TestConfigArgs(t *testing.T) {
}
func TestNewConfig(t *testing.T) {
t.Parallel()
ids := [...]string{"org.chromium.Chromium", "dev.vencord.Vesktop"}
type newTestCase struct {
@@ -107,6 +112,8 @@ func TestNewConfig(t *testing.T) {
}
t.Run(name.String(), func(t *testing.T) {
t.Parallel()
if gotC := dbus.NewConfig(tc.id, tc.args[0], tc.args[1]); !reflect.DeepEqual(gotC, tc.want) {
t.Errorf("NewConfig(%q, %t, %t) = %v, want %v",
tc.id, tc.args[0], tc.args[1],

View File

@@ -65,7 +65,7 @@ func TestProxyStartWaitCloseString(t *testing.T) {
}
const (
stubProxyTimeout = 30 * time.Second
stubProxyTimeout = 5 * time.Second
)
func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
@@ -99,8 +99,7 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
}
if err := p.Start(); !errors.Is(err, syscall.ENOTRECOVERABLE) {
t.Errorf("Start: error = %q, wantErr %q",
err, syscall.ENOTRECOVERABLE)
t.Errorf("Start: error = %q, wantErr %q", err, syscall.ENOTRECOVERABLE)
return
}
})
@@ -115,71 +114,57 @@ func testProxyFinaliseStartWaitCloseString(t *testing.T, useSandbox bool) {
var final *dbus.Final
t.Run("finalise", func(t *testing.T) {
if v, err := dbus.Finalise(tc[0].bus, tc[1].bus, tc[0].c, tc[1].c); err != nil {
t.Errorf("Finalise: error = %v, wantErr %v",
err, tc[0].wantErr)
t.Errorf("Finalise: error = %v, wantErr %v", err, tc[0].wantErr)
return
} else {
final = v
}
})
t.Run("run", func(t *testing.T) {
ctx, cancel := context.WithTimeout(t.Context(), stubProxyTimeout)
defer cancel()
output := new(strings.Builder)
if !useSandbox {
p = dbus.NewDirect(ctx, message.NewMsg(nil), final, output)
} else {
p = dbus.New(ctx, message.NewMsg(nil), final, output)
ctx, cancel := context.WithTimeout(t.Context(), stubProxyTimeout)
defer cancel()
output := new(strings.Builder)
if !useSandbox {
p = dbus.NewDirect(ctx, message.NewMsg(nil), final, output)
} else {
p = dbus.New(ctx, message.NewMsg(nil), final, output)
}
{ // check invalid wait behaviour
wantErr := "dbus: not started"
if err := p.Wait(); err == nil || err.Error() != wantErr {
t.Errorf("Wait: error = %v, wantErr %v", err, wantErr)
}
}
t.Run("invalid wait", func(t *testing.T) {
wantErr := "dbus: not started"
if err := p.Wait(); err == nil || err.Error() != wantErr {
t.Errorf("Wait: error = %v, wantErr %v",
err, wantErr)
}
})
t.Run("string", func(t *testing.T) {
want := "(unused dbus proxy)"
if got := p.String(); got != want {
t.Errorf("String: %q, want %q",
got, want)
return
}
})
if err := p.Start(); err != nil {
t.Fatalf("Start: error = %v",
err)
{ // check string behaviour
want := "(unused dbus proxy)"
if got := p.String(); got != want {
t.Errorf("String: %q, want %q", got, want)
return
}
}
t.Run("string", func(t *testing.T) {
wantSubstr := fmt.Sprintf("%s --args=3 --fd=4", os.Args[0])
if useSandbox {
wantSubstr = `argv: ["xdg-dbus-proxy" "--args=3" "--fd=4"], filter: true, rules: 0, flags: 0x1, presets: 0xf`
}
if got := p.String(); !strings.Contains(got, wantSubstr) {
t.Errorf("String: %q, want %q",
got, wantSubstr)
return
}
})
if err := p.Start(); err != nil {
t.Fatalf("Start: error = %v", err)
}
t.Run("wait", func(t *testing.T) {
done := make(chan struct{})
go func() {
if err := p.Wait(); err != nil {
t.Errorf("Wait: error = %v\noutput: %s",
err, output.String())
}
close(done)
}()
p.Close()
<-done
})
})
{ // check running string behaviour
wantSubstr := fmt.Sprintf("%s --args=3 --fd=4", os.Args[0])
if useSandbox {
wantSubstr = `argv: ["xdg-dbus-proxy" "--args=3" "--fd=4"], filter: true, rules: 0, flags: 0x1, presets: 0xf`
}
if got := p.String(); !strings.Contains(got, wantSubstr) {
t.Errorf("String: %q, want %q",
got, wantSubstr)
return
}
}
p.Close()
if err := p.Wait(); err != nil {
t.Errorf("Wait: error = %v\noutput: %s", err, output.String())
}
})
}
}

View File

@@ -146,7 +146,7 @@ func (p *Proxy) Wait() error {
return errors.New("dbus: not started")
}
errs := make([]error, 3)
var errs [3]error
errs[0] = p.helper.Wait()
if errors.Is(errs[0], context.Canceled) &&
@@ -165,7 +165,7 @@ func (p *Proxy) Wait() error {
}
}
return errors.Join(errs...)
return errors.Join(errs[:]...)
}
// Close cancels the context passed to the helper instance attached to xdg-dbus-proxy.

View File

@@ -8,8 +8,4 @@ import (
"hakurei.app/helper"
)
func TestMain(m *testing.M) {
container.TryArgv0(nil)
helper.InternalHelperStub()
os.Exit(m.Run())
}
func TestMain(m *testing.M) { container.TryArgv0(nil); helper.InternalHelperStub(); os.Exit(m.Run()) }

View File

@@ -16,6 +16,8 @@ import (
)
func TestDBusProxyOp(t *testing.T) {
t.Parallel()
checkOpBehaviour(t, []opBehaviourTestCase{
{"dbusProxyStart", 0xdeadbeef, 0xff, &dbusProxyOp{
final: dbusNewFinalSample(4),
@@ -377,6 +379,8 @@ func dbusNewFinalSample(v int) *dbus.Final {
}
func TestLinePrefixWriter(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
prefix string
@@ -588,6 +592,7 @@ func TestLinePrefixWriter(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
gotPt := make([]string, 0, len(tc.wantPt))
out := &linePrefixWriter{
prefix: tc.prefix,
@@ -631,11 +636,11 @@ func TestLinePrefixWriter(t *testing.T) {
}
wantDump := make([]string, len(tc.want)+len(tc.wantExt))
for i, m := range tc.want {
wantDump[i] = tc.prefix + m
for i, want := range tc.want {
wantDump[i] = tc.prefix + want
}
for i, m := range tc.wantExt {
wantDump[len(tc.want)+i] = m
for i, want := range tc.wantExt {
wantDump[len(tc.want)+i] = want
}
t.Run("dump", func(t *testing.T) {
got := make([]string, 0, len(wantDump))

View File

@@ -1,14 +1,11 @@
package system
import (
"io"
"io/fs"
"log"
"os"
"reflect"
"slices"
"testing"
"time"
"unsafe"
"hakurei.app/container/stub"
@@ -42,10 +39,12 @@ func checkOpBehaviour(t *testing.T, testCases []opBehaviourTestCase) {
t.Run("behaviour", func(t *testing.T) {
t.Helper()
t.Parallel()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Helper()
t.Parallel()
var ec *Criteria
if tc.ec != 0xff {
@@ -94,10 +93,12 @@ func checkOpsBuilder(t *testing.T, fname string, testCases []opsBuilderTestCase)
t.Run("build", func(t *testing.T) {
t.Helper()
t.Parallel()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Helper()
t.Parallel()
sys, s := InternalNew(t, tc.exp, tc.uid)
defer stub.HandleExit(t)
@@ -126,10 +127,12 @@ func checkOpIs(t *testing.T, testCases []opIsTestCase) {
t.Run("is", func(t *testing.T) {
t.Helper()
t.Parallel()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Helper()
t.Parallel()
if got := tc.op.Is(tc.v); got != tc.want {
t.Errorf("Is: %v, want %v", got, tc.want)
@@ -153,10 +156,12 @@ func checkOpMeta(t *testing.T, testCases []opMetaTestCase) {
t.Run("meta", func(t *testing.T) {
t.Helper()
t.Parallel()
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Helper()
t.Parallel()
t.Run("type", func(t *testing.T) {
t.Helper()
@@ -186,34 +191,6 @@ func checkOpMeta(t *testing.T, testCases []opMetaTestCase) {
})
}
type stubFi struct {
size int64
isDir bool
}
func (stubFi) Name() string { panic("unreachable") }
func (fi stubFi) Size() int64 { return fi.size }
func (stubFi) Mode() fs.FileMode { panic("unreachable") }
func (stubFi) ModTime() time.Time { panic("unreachable") }
func (fi stubFi) IsDir() bool { return fi.isDir }
func (stubFi) Sys() any { panic("unreachable") }
type readerOsFile struct {
closed bool
io.Reader
}
func (*readerOsFile) Name() string { panic("unreachable") }
func (*readerOsFile) Write([]byte) (int, error) { panic("unreachable") }
func (*readerOsFile) Stat() (fs.FileInfo, error) { panic("unreachable") }
func (r *readerOsFile) Close() error {
if r.closed {
return os.ErrClosed
}
r.closed = true
return nil
}
// InternalNew initialises [I] with a stub syscallDispatcher.
func InternalNew(t *testing.T, want stub.Expect, uid int) (*I, *stub.Stub[syscallDispatcher]) {
k := &kstub{stub.New(t, func(s *stub.Stub[syscallDispatcher]) syscallDispatcher { return &kstub{s} }, want)}

View File

@@ -8,6 +8,8 @@ import (
)
func TestHardlinkOp(t *testing.T) {
t.Parallel()
checkOpBehaviour(t, []opBehaviourTestCase{
{"link", 0xdeadbeef, 0xff, &hardlinkOp{hst.EPulse, "/run/user/1000/hakurei/9663730666a44cfc2a81610379e02ed6/pulse", "/run/user/1000/pulse/native"}, []stub.Call{
call("verbose", stub.ExpectArgs{[]any{"linking", &hardlinkOp{hst.EPulse, "/run/user/1000/hakurei/9663730666a44cfc2a81610379e02ed6/pulse", "/run/user/1000/pulse/native"}}}, nil, nil),

View File

@@ -8,6 +8,8 @@ import (
)
func TestMkdirOp(t *testing.T) {
t.Parallel()
checkOpBehaviour(t, []opBehaviourTestCase{
{"mkdir", 0xdeadbeef, 0xff, &mkdirOp{User, "/tmp/hakurei.0/f2f3bcd492d0266438fa9bf164fe90d9", 0711, false}, []stub.Call{
call("verbose", stub.ExpectArgs{[]any{"ensuring directory", &mkdirOp{User, "/tmp/hakurei.0/f2f3bcd492d0266438fa9bf164fe90d9", 0711, false}}}, nil, nil),

View File

@@ -13,6 +13,8 @@ import (
)
func TestOpError(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
err error
@@ -49,6 +51,8 @@ func TestOpError(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
t.Run("error", func(t *testing.T) {
if got := tc.err.Error(); got != tc.s {
t.Errorf("Error: %q, want %q", got, tc.s)
@@ -88,6 +92,8 @@ func TestOpError(t *testing.T) {
}
func TestPrintJoinedError(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
err error
@@ -123,6 +129,7 @@ func TestPrintJoinedError(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var got [][]any
printJoinedError(func(v ...any) { got = append(got, v) }, "not a joined error:", tc.err)
if !reflect.DeepEqual(got, tc.want) {

View File

@@ -16,6 +16,8 @@ import (
)
func TestCriteria(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
ec, t hst.Enablement
@@ -28,6 +30,7 @@ func TestCriteria(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var criteria *Criteria
if tc.ec != 0xff {
criteria = (*Criteria)(&tc.ec)
@@ -41,6 +44,8 @@ func TestCriteria(t *testing.T) {
}
func TestTypeString(t *testing.T) {
t.Parallel()
testCases := []struct {
e hst.Enablement
want string
@@ -58,6 +63,7 @@ func TestTypeString(t *testing.T) {
for _, tc := range testCases {
t.Run("label type string "+strconv.Itoa(int(tc.e)), func(t *testing.T) {
t.Parallel()
if got := TypeString(tc.e); got != tc.want {
t.Errorf("TypeString: %q, want %q", got, tc.want)
}
@@ -66,6 +72,8 @@ func TestTypeString(t *testing.T) {
}
func TestNew(t *testing.T) {
t.Parallel()
t.Run("panic", func(t *testing.T) {
t.Run("ctx", func(t *testing.T) {
defer func() {
@@ -108,6 +116,8 @@ func TestNew(t *testing.T) {
}
func TestEqual(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
sys *I
@@ -175,6 +185,8 @@ func TestEqual(t *testing.T) {
}
func TestCommitRevert(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
f func(sys *I)
@@ -252,6 +264,8 @@ func TestCommitRevert(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var ec *Criteria
if tc.ec != 0xff {
ec = (*Criteria)(&tc.ec)

View File

@@ -86,6 +86,8 @@ func (conn *stubWaylandConn) Close() error {
}
func TestWaylandOp(t *testing.T) {
t.Parallel()
checkOpBehaviour(t, []opBehaviourTestCase{
{"attach", 0xdeadbeef, 0xff, &waylandOp{nil,
"/tmp/hakurei.1971/ebf083d1b175911782d413369b64ce7c/wayland",

View File

@@ -9,6 +9,8 @@ import (
)
func TestXHostOp(t *testing.T) {
t.Parallel()
checkOpBehaviour(t, []opBehaviourTestCase{
{"xcbChangeHosts revert", 0xbeef, hst.EX11, xhostOp("chronos"), []stub.Call{
call("verbosef", stub.ExpectArgs{"inserting entry %s to X11", []any{xhostOp("chronos")}}, nil, nil),