diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-13 04:38:48 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-13 04:38:48 +0900 |
| commit | 7638a44fa613f23434318bdf136723aa010e8638 (patch) | |
| tree | 7b5270ed4e9b6d7f1ee0f28c58d8077aa1d18005 /system | |
| parent | a14b6535a66cb7ac0fc4827f767ffaee0ce04b57 (diff) | |
treewide: parallel tests
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>
Diffstat (limited to 'system')
| -rw-r--r-- | system/acl_test.go | 2 | ||||
| -rw-r--r-- | system/dbus/address_escape_test.go | 4 | ||||
| -rw-r--r-- | system/dbus/address_test.go | 4 | ||||
| -rw-r--r-- | system/dbus/config_test.go | 7 | ||||
| -rw-r--r-- | system/dbus/dbus_test.go | 97 | ||||
| -rw-r--r-- | system/dbus/proc.go | 4 | ||||
| -rw-r--r-- | system/dbus/proc_test.go | 6 | ||||
| -rw-r--r-- | system/dbus_test.go | 13 | ||||
| -rw-r--r-- | system/dispatcher_test.go | 39 | ||||
| -rw-r--r-- | system/link_test.go | 2 | ||||
| -rw-r--r-- | system/mkdir_test.go | 2 | ||||
| -rw-r--r-- | system/output_test.go | 7 | ||||
| -rw-r--r-- | system/system_test.go | 14 | ||||
| -rw-r--r-- | system/wayland_test.go | 2 | ||||
| -rw-r--r-- | system/xhost_test.go | 2 |
15 files changed, 107 insertions, 98 deletions
diff --git a/system/acl_test.go b/system/acl_test.go index 992271a2..a7465f25 100644 --- a/system/acl_test.go +++ b/system/acl_test.go @@ -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{ diff --git a/system/dbus/address_escape_test.go b/system/dbus/address_escape_test.go index 3ea2cd26..4ef48f8b 100644 --- a/system/dbus/address_escape_test.go +++ b/system/dbus/address_escape_test.go @@ -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 { diff --git a/system/dbus/address_test.go b/system/dbus/address_test.go index 6bd0627b..5de90535 100644 --- a/system/dbus/address_test.go +++ b/system/dbus/address_test.go @@ -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) { diff --git a/system/dbus/config_test.go b/system/dbus/config_test.go index 84477e40..644c766f 100644 --- a/system/dbus/config_test.go +++ b/system/dbus/config_test.go @@ -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], diff --git a/system/dbus/dbus_test.go b/system/dbus/dbus_test.go index 299a4637..abe324ba 100644 --- a/system/dbus/dbus_test.go +++ b/system/dbus/dbus_test.go @@ -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) - } - }) + { // 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) { - 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) + } - if err := p.Start(); err != nil { - t.Fatalf("Start: error = %v", - err) + { // 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 + } + } - 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 - } - }) - - 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 - }) - }) + p.Close() + if err := p.Wait(); err != nil { + t.Errorf("Wait: error = %v\noutput: %s", err, output.String()) + } }) } } diff --git a/system/dbus/proc.go b/system/dbus/proc.go index 005b9142..b386eecb 100644 --- a/system/dbus/proc.go +++ b/system/dbus/proc.go @@ -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. diff --git a/system/dbus/proc_test.go b/system/dbus/proc_test.go index 8b41c04c..a3ce1631 100644 --- a/system/dbus/proc_test.go +++ b/system/dbus/proc_test.go @@ -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()) } diff --git a/system/dbus_test.go b/system/dbus_test.go index 0bc7b7fd..2a1f12db 100644 --- a/system/dbus_test.go +++ b/system/dbus_test.go @@ -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)) diff --git a/system/dispatcher_test.go b/system/dispatcher_test.go index 9a1a0d92..5edc2751 100644 --- a/system/dispatcher_test.go +++ b/system/dispatcher_test.go @@ -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)} diff --git a/system/link_test.go b/system/link_test.go index 20855968..065f9fe7 100644 --- a/system/link_test.go +++ b/system/link_test.go @@ -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), diff --git a/system/mkdir_test.go b/system/mkdir_test.go index 7d790750..e2f8c11d 100644 --- a/system/mkdir_test.go +++ b/system/mkdir_test.go @@ -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), diff --git a/system/output_test.go b/system/output_test.go index d395b13c..c0cbfdfe 100644 --- a/system/output_test.go +++ b/system/output_test.go @@ -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) { diff --git a/system/system_test.go b/system/system_test.go index 6d217475..83d97a69 100644 --- a/system/system_test.go +++ b/system/system_test.go @@ -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) diff --git a/system/wayland_test.go b/system/wayland_test.go index d6a3b93b..367b1e5e 100644 --- a/system/wayland_test.go +++ b/system/wayland_test.go @@ -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", diff --git a/system/xhost_test.go b/system/xhost_test.go index ad3ba89d..bcff3a54 100644 --- a/system/xhost_test.go +++ b/system/xhost_test.go @@ -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), |
