aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/dbus
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-13 04:38:48 +0900
committerOphestra <cat@gensokyo.uk>2025-10-13 04:38:48 +0900
commit7638a44fa613f23434318bdf136723aa010e8638 (patch)
tree7b5270ed4e9b6d7f1ee0f28c58d8077aa1d18005 /system/dbus
parenta14b6535a66cb7ac0fc4827f767ffaee0ce04b57 (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/dbus')
-rw-r--r--system/dbus/address_escape_test.go4
-rw-r--r--system/dbus/address_test.go4
-rw-r--r--system/dbus/config_test.go7
-rw-r--r--system/dbus/dbus_test.go97
-rw-r--r--system/dbus/proc.go4
-rw-r--r--system/dbus/proc_test.go6
6 files changed, 59 insertions, 63 deletions
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()) }