Skip to content

Commit 5676bf5

Browse files
committed
feat: Add parallel test execution to improve runtime
- added linter to ensure parallel tests - added t.Parallel and t.Helper accordingly
1 parent c4f708b commit 5676bf5

File tree

14 files changed

+441
-34
lines changed

14 files changed

+441
-34
lines changed

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ linters:
88
- goimports
99
- gofmt
1010
- gofumpt
11+
- paralleltest
12+
- tenv
13+
- thelper
14+
- tparallel
1115

1216
linters-settings:
1317
goimports:

args/args_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
)
1313

1414
func TestArgs(t *testing.T) {
15+
t.Parallel()
16+
1517
tests := []struct {
1618
Args []string
1719
ExpectedCalls []*ast.Call
@@ -97,6 +99,8 @@ func TestArgs(t *testing.T) {
9799

98100
for i, test := range tests {
99101
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
102+
t.Parallel()
103+
100104
calls, globals := args.Parse(test.Args...)
101105
assert.Equal(t, test.ExpectedCalls, calls)
102106
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {

internal/fingerprint/sources_checksum_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
)
88

99
func TestNormalizeFilename(t *testing.T) {
10+
t.Parallel()
11+
1012
tests := []struct {
1113
In, Out string
1214
}{

internal/fingerprint/task_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
// | false | true | false |
2727
// | false | false | false |
2828
func TestIsTaskUpToDate(t *testing.T) {
29+
t.Parallel()
30+
2931
tests := []struct {
3032
name string
3133
task *ast.Task
@@ -150,6 +152,8 @@ func TestIsTaskUpToDate(t *testing.T) {
150152
}
151153
for _, tt := range tests {
152154
t.Run(tt.name, func(t *testing.T) {
155+
t.Parallel()
156+
153157
mockStatusChecker := mocks.NewStatusCheckable(t)
154158
if tt.setupMockStatusChecker != nil {
155159
tt.setupMockStatusChecker(mockStatusChecker)

internal/omap/orderedmap_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
func TestFromMap(t *testing.T) {
12+
t.Parallel()
13+
1214
m := map[int]string{3: "three", 1: "one", 2: "two"}
1315
om := FromMap(m)
1416
assert.Len(t, om.m, 3)
@@ -20,6 +22,8 @@ func TestFromMap(t *testing.T) {
2022
}
2123

2224
func TestSetGetExists(t *testing.T) {
25+
t.Parallel()
26+
2327
om := New[int, string]()
2428
assert.False(t, om.Exists(1))
2529
assert.Equal(t, "", om.Get(1))
@@ -29,6 +33,8 @@ func TestSetGetExists(t *testing.T) {
2933
}
3034

3135
func TestSort(t *testing.T) {
36+
t.Parallel()
37+
3238
om := New[int, string]()
3339
om.Set(3, "three")
3440
om.Set(1, "one")
@@ -38,6 +44,8 @@ func TestSort(t *testing.T) {
3844
}
3945

4046
func TestSortFunc(t *testing.T) {
47+
t.Parallel()
48+
4149
om := New[int, string]()
4250
om.Set(3, "three")
4351
om.Set(1, "one")
@@ -49,6 +57,8 @@ func TestSortFunc(t *testing.T) {
4957
}
5058

5159
func TestKeysValues(t *testing.T) {
60+
t.Parallel()
61+
5262
om := New[int, string]()
5363
om.Set(3, "three")
5464
om.Set(1, "one")
@@ -58,6 +68,8 @@ func TestKeysValues(t *testing.T) {
5868
}
5969

6070
func Range(t *testing.T) {
71+
t.Helper()
72+
6173
om := New[int, string]()
6274
om.Set(3, "three")
6375
om.Set(1, "one")
@@ -81,6 +93,8 @@ func Range(t *testing.T) {
8193
}
8294

8395
func TestOrderedMapMerge(t *testing.T) {
96+
t.Parallel()
97+
8498
om1 := New[string, int]()
8599
om1.Set("a", 1)
86100
om1.Set("b", 2)
@@ -104,6 +118,8 @@ func TestOrderedMapMerge(t *testing.T) {
104118
}
105119

106120
func TestUnmarshalYAML(t *testing.T) {
121+
t.Parallel()
122+
107123
yamlString := `
108124
3: three
109125
1: one

internal/output/output_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
)
2020

2121
func TestInterleaved(t *testing.T) {
22+
t.Parallel()
23+
2224
var b bytes.Buffer
2325
var o output.Output = output.Interleaved{}
2426
w, _, _ := o.WrapWriter(&b, io.Discard, "", nil)
@@ -30,6 +32,8 @@ func TestInterleaved(t *testing.T) {
3032
}
3133

3234
func TestGroup(t *testing.T) {
35+
t.Parallel()
36+
3337
var b bytes.Buffer
3438
var o output.Output = output.Group{}
3539
stdOut, stdErr, cleanup := o.WrapWriter(&b, io.Discard, "", nil)
@@ -48,6 +52,8 @@ func TestGroup(t *testing.T) {
4852
}
4953

5054
func TestGroupWithBeginEnd(t *testing.T) {
55+
t.Parallel()
56+
5157
tmpl := templater.Cache{
5258
Vars: &ast.Vars{
5359
OrderedMap: omap.FromMap(map[string]ast.Var{
@@ -61,6 +67,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
6167
End: "::endgroup::",
6268
}
6369
t.Run("simple", func(t *testing.T) {
70+
t.Parallel()
71+
6472
var b bytes.Buffer
6573
w, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)
6674

@@ -72,6 +80,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
7280
assert.Equal(t, "::group::example-value\nfoo\nbar\nbaz\n::endgroup::\n", b.String())
7381
})
7482
t.Run("no output", func(t *testing.T) {
83+
t.Parallel()
84+
7585
var b bytes.Buffer
7686
_, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)
7787
require.NoError(t, cleanup(nil))
@@ -80,6 +90,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
8090
}
8191

8292
func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
93+
t.Parallel()
94+
8395
var b bytes.Buffer
8496
var o output.Output = output.Group{
8597
ErrorOnly: true,
@@ -94,6 +106,8 @@ func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
94106
}
95107

96108
func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
109+
t.Parallel()
110+
97111
var b bytes.Buffer
98112
var o output.Output = output.Group{
99113
ErrorOnly: true,
@@ -107,7 +121,7 @@ func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
107121
assert.Equal(t, "std-out\nstd-err\n", b.String())
108122
}
109123

110-
func TestPrefixed(t *testing.T) {
124+
func TestPrefixed(t *testing.T) { //nolint:paralleltest // cannot run in parallel
111125
var b bytes.Buffer
112126
l := &logger.Logger{
113127
Color: false,
@@ -116,7 +130,7 @@ func TestPrefixed(t *testing.T) {
116130
var o output.Output = output.NewPrefixed(l)
117131
w, _, cleanup := o.WrapWriter(&b, io.Discard, "prefix", nil)
118132

119-
t.Run("simple use cases", func(t *testing.T) {
133+
t.Run("simple use cases", func(t *testing.T) { //nolint:paralleltest // cannot run in parallel
120134
b.Reset()
121135

122136
fmt.Fprintln(w, "foo\nbar")
@@ -126,7 +140,7 @@ func TestPrefixed(t *testing.T) {
126140
require.NoError(t, cleanup(nil))
127141
})
128142

129-
t.Run("multiple writes for a single line", func(t *testing.T) {
143+
t.Run("multiple writes for a single line", func(t *testing.T) { //nolint:paralleltest // cannot run in parallel
130144
b.Reset()
131145

132146
for _, char := range []string{"T", "e", "s", "t", "!"} {
@@ -140,6 +154,8 @@ func TestPrefixed(t *testing.T) {
140154
}
141155

142156
func TestPrefixedWithColor(t *testing.T) {
157+
t.Parallel()
158+
143159
color.NoColor = false
144160

145161
var b bytes.Buffer
@@ -155,6 +171,8 @@ func TestPrefixedWithColor(t *testing.T) {
155171
}
156172

157173
t.Run("colors should loop", func(t *testing.T) {
174+
t.Parallel()
175+
158176
for i, w := range writers {
159177
b.Reset()
160178

@@ -164,7 +182,11 @@ func TestPrefixedWithColor(t *testing.T) {
164182
l.FOutf(&prefix, color, fmt.Sprintf("prefix-%d", i))
165183

166184
fmt.Fprintln(w, "foo\nbar")
167-
assert.Equal(t, fmt.Sprintf("[%s] foo\n[%s] bar\n", prefix.String(), prefix.String()), b.String())
185+
assert.Equal(
186+
t,
187+
fmt.Sprintf("[%s] foo\n[%s] bar\n", prefix.String(), prefix.String()),
188+
b.String(),
189+
)
168190
}
169191
})
170192
}

internal/sort/sorter_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
12+
t.Parallel()
13+
1214
task1 := &ast.Task{Task: "task1"}
1315
task2 := &ast.Task{Task: "task2"}
1416
task3 := &ast.Task{Task: "ns1:task3"}
@@ -40,6 +42,8 @@ func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
4042

4143
for _, tt := range tests {
4244
t.Run(tt.name, func(t *testing.T) {
45+
t.Parallel()
46+
4347
s := &AlphaNumericWithRootTasksFirst{}
4448
s.Sort(tt.tasks)
4549
assert.Equal(t, tt.want, tt.tasks)
@@ -48,6 +52,8 @@ func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
4852
}
4953

5054
func TestAlphaNumeric_Sort(t *testing.T) {
55+
t.Parallel()
56+
5157
task1 := &ast.Task{Task: "task1"}
5258
task2 := &ast.Task{Task: "task2"}
5359
task3 := &ast.Task{Task: "ns1:task3"}
@@ -69,6 +75,8 @@ func TestAlphaNumeric_Sort(t *testing.T) {
6975

7076
for _, tt := range tests {
7177
t.Run(tt.name, func(t *testing.T) {
78+
t.Parallel()
79+
7280
s := &AlphaNumeric{}
7381
s.Sort(tt.tasks)
7482
assert.Equal(t, tt.tasks, tt.want)

internal/summary/summary_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
)
1414

1515
func TestPrintsDependenciesIfPresent(t *testing.T) {
16+
t.Parallel()
17+
1618
buffer, l := createDummyLogger()
1719
task := &ast.Task{
1820
Deps: []*ast.Dep{
@@ -38,6 +40,8 @@ func createDummyLogger() (*bytes.Buffer, logger.Logger) {
3840
}
3941

4042
func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
43+
t.Parallel()
44+
4145
buffer, l := createDummyLogger()
4246
task := &ast.Task{
4347
Deps: []*ast.Dep{},
@@ -49,6 +53,8 @@ func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
4953
}
5054

5155
func TestPrintTaskName(t *testing.T) {
56+
t.Parallel()
57+
5258
buffer, l := createDummyLogger()
5359
task := &ast.Task{
5460
Task: "my-task-name",
@@ -60,6 +66,8 @@ func TestPrintTaskName(t *testing.T) {
6066
}
6167

6268
func TestPrintTaskCommandsIfPresent(t *testing.T) {
69+
t.Parallel()
70+
6371
buffer, l := createDummyLogger()
6472
task := &ast.Task{
6573
Cmds: []*ast.Cmd{
@@ -78,6 +86,8 @@ func TestPrintTaskCommandsIfPresent(t *testing.T) {
7886
}
7987

8088
func TestDoesNotPrintCommandIfMissing(t *testing.T) {
89+
t.Parallel()
90+
8191
buffer, l := createDummyLogger()
8292
task := &ast.Task{
8393
Cmds: []*ast.Cmd{},
@@ -89,6 +99,8 @@ func TestDoesNotPrintCommandIfMissing(t *testing.T) {
8999
}
90100

91101
func TestLayout(t *testing.T) {
102+
t.Parallel()
103+
92104
buffer, l := createDummyLogger()
93105
task := &ast.Task{
94106
Task: "sample-task",
@@ -123,6 +135,8 @@ commands:
123135
}
124136

125137
func TestPrintDescriptionAsFallback(t *testing.T) {
138+
t.Parallel()
139+
126140
buffer, l := createDummyLogger()
127141
taskWithoutSummary := &ast.Task{
128142
Desc: "description",
@@ -150,6 +164,8 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
150164
}
151165

152166
func TestPrintAllWithSpaces(t *testing.T) {
167+
t.Parallel()
168+
153169
buffer, l := createDummyLogger()
154170

155171
t1 := &ast.Task{Task: "t1"}

0 commit comments

Comments
 (0)