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
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:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()) }
|
||||
|
||||
Reference in New Issue
Block a user