Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add parallel test execution to improve runtime #1882

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ linters:
- goimports
- gofmt
- gofumpt
- paralleltest
- tenv
- thelper
- tparallel

linters-settings:
goimports:
Expand Down
4 changes: 4 additions & 0 deletions args/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

func TestArgs(t *testing.T) {
t.Parallel()

tests := []struct {
Args []string
ExpectedCalls []*ast.Call
Expand Down Expand Up @@ -97,6 +99,8 @@ func TestArgs(t *testing.T) {

for i, test := range tests {
t.Run(fmt.Sprintf("TestArgs%d", i+1), func(t *testing.T) {
t.Parallel()

calls, globals := args.Parse(test.Args...)
assert.Equal(t, test.ExpectedCalls, calls)
if test.ExpectedGlobals.Len() > 0 || globals.Len() > 0 {
Expand Down
2 changes: 2 additions & 0 deletions internal/fingerprint/sources_checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
)

func TestNormalizeFilename(t *testing.T) {
t.Parallel()

tests := []struct {
In, Out string
}{
Expand Down
4 changes: 4 additions & 0 deletions internal/fingerprint/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
// | false | true | false |
// | false | false | false |
func TestIsTaskUpToDate(t *testing.T) {
t.Parallel()

tests := []struct {
name string
task *ast.Task
Expand Down Expand Up @@ -150,6 +152,8 @@ func TestIsTaskUpToDate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

mockStatusChecker := mocks.NewStatusCheckable(t)
if tt.setupMockStatusChecker != nil {
tt.setupMockStatusChecker(mockStatusChecker)
Expand Down
16 changes: 16 additions & 0 deletions internal/omap/orderedmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestFromMap(t *testing.T) {
t.Parallel()

m := map[int]string{3: "three", 1: "one", 2: "two"}
om := FromMap(m)
assert.Len(t, om.m, 3)
Expand All @@ -20,6 +22,8 @@ func TestFromMap(t *testing.T) {
}

func TestSetGetExists(t *testing.T) {
t.Parallel()

om := New[int, string]()
assert.False(t, om.Exists(1))
assert.Equal(t, "", om.Get(1))
Expand All @@ -29,6 +33,8 @@ func TestSetGetExists(t *testing.T) {
}

func TestSort(t *testing.T) {
t.Parallel()

om := New[int, string]()
om.Set(3, "three")
om.Set(1, "one")
Expand All @@ -38,6 +44,8 @@ func TestSort(t *testing.T) {
}

func TestSortFunc(t *testing.T) {
t.Parallel()

om := New[int, string]()
om.Set(3, "three")
om.Set(1, "one")
Expand All @@ -49,6 +57,8 @@ func TestSortFunc(t *testing.T) {
}

func TestKeysValues(t *testing.T) {
t.Parallel()

om := New[int, string]()
om.Set(3, "three")
om.Set(1, "one")
Expand All @@ -58,6 +68,8 @@ func TestKeysValues(t *testing.T) {
}

func Range(t *testing.T) {
t.Helper()

om := New[int, string]()
om.Set(3, "three")
om.Set(1, "one")
Expand All @@ -81,6 +93,8 @@ func Range(t *testing.T) {
}

func TestOrderedMapMerge(t *testing.T) {
t.Parallel()

om1 := New[string, int]()
om1.Set("a", 1)
om1.Set("b", 2)
Expand All @@ -104,6 +118,8 @@ func TestOrderedMapMerge(t *testing.T) {
}

func TestUnmarshalYAML(t *testing.T) {
t.Parallel()

yamlString := `
3: three
1: one
Expand Down
30 changes: 26 additions & 4 deletions internal/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
)

func TestInterleaved(t *testing.T) {
t.Parallel()

var b bytes.Buffer
var o output.Output = output.Interleaved{}
w, _, _ := o.WrapWriter(&b, io.Discard, "", nil)
Expand All @@ -30,6 +32,8 @@ func TestInterleaved(t *testing.T) {
}

func TestGroup(t *testing.T) {
t.Parallel()

var b bytes.Buffer
var o output.Output = output.Group{}
stdOut, stdErr, cleanup := o.WrapWriter(&b, io.Discard, "", nil)
Expand All @@ -48,6 +52,8 @@ func TestGroup(t *testing.T) {
}

func TestGroupWithBeginEnd(t *testing.T) {
t.Parallel()

tmpl := templater.Cache{
Vars: &ast.Vars{
OrderedMap: omap.FromMap(map[string]ast.Var{
Expand All @@ -61,6 +67,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
End: "::endgroup::",
}
t.Run("simple", func(t *testing.T) {
t.Parallel()

var b bytes.Buffer
w, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)

Expand All @@ -72,6 +80,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
assert.Equal(t, "::group::example-value\nfoo\nbar\nbaz\n::endgroup::\n", b.String())
})
t.Run("no output", func(t *testing.T) {
t.Parallel()

var b bytes.Buffer
_, _, cleanup := o.WrapWriter(&b, io.Discard, "", &tmpl)
require.NoError(t, cleanup(nil))
Expand All @@ -80,6 +90,8 @@ func TestGroupWithBeginEnd(t *testing.T) {
}

func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
t.Parallel()

var b bytes.Buffer
var o output.Output = output.Group{
ErrorOnly: true,
Expand All @@ -94,6 +106,8 @@ func TestGroupErrorOnlySwallowsOutputOnNoError(t *testing.T) {
}

func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
t.Parallel()

var b bytes.Buffer
var o output.Output = output.Group{
ErrorOnly: true,
Expand All @@ -107,7 +121,7 @@ func TestGroupErrorOnlyShowsOutputOnError(t *testing.T) {
assert.Equal(t, "std-out\nstd-err\n", b.String())
}

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

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

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

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

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

func TestPrefixedWithColor(t *testing.T) {
t.Parallel()

color.NoColor = false

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

t.Run("colors should loop", func(t *testing.T) {
t.Parallel()

for i, w := range writers {
b.Reset()

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

fmt.Fprintln(w, "foo\nbar")
assert.Equal(t, fmt.Sprintf("[%s] foo\n[%s] bar\n", prefix.String(), prefix.String()), b.String())
assert.Equal(
t,
fmt.Sprintf("[%s] foo\n[%s] bar\n", prefix.String(), prefix.String()),
b.String(),
)
}
})
}
8 changes: 8 additions & 0 deletions internal/sort/sorter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
t.Parallel()

task1 := &ast.Task{Task: "task1"}
task2 := &ast.Task{Task: "task2"}
task3 := &ast.Task{Task: "ns1:task3"}
Expand Down Expand Up @@ -40,6 +42,8 @@ func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

s := &AlphaNumericWithRootTasksFirst{}
s.Sort(tt.tasks)
assert.Equal(t, tt.want, tt.tasks)
Expand All @@ -48,6 +52,8 @@ func TestAlphaNumericWithRootTasksFirst_Sort(t *testing.T) {
}

func TestAlphaNumeric_Sort(t *testing.T) {
t.Parallel()

task1 := &ast.Task{Task: "task1"}
task2 := &ast.Task{Task: "task2"}
task3 := &ast.Task{Task: "ns1:task3"}
Expand All @@ -69,6 +75,8 @@ func TestAlphaNumeric_Sort(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

s := &AlphaNumeric{}
s.Sort(tt.tasks)
assert.Equal(t, tt.tasks, tt.want)
Expand Down
16 changes: 16 additions & 0 deletions internal/summary/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
)

func TestPrintsDependenciesIfPresent(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
task := &ast.Task{
Deps: []*ast.Dep{
Expand All @@ -38,6 +40,8 @@ func createDummyLogger() (*bytes.Buffer, logger.Logger) {
}

func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
task := &ast.Task{
Deps: []*ast.Dep{},
Expand All @@ -49,6 +53,8 @@ func TestDoesNotPrintDependenciesIfMissing(t *testing.T) {
}

func TestPrintTaskName(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
task := &ast.Task{
Task: "my-task-name",
Expand All @@ -60,6 +66,8 @@ func TestPrintTaskName(t *testing.T) {
}

func TestPrintTaskCommandsIfPresent(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
task := &ast.Task{
Cmds: []*ast.Cmd{
Expand All @@ -78,6 +86,8 @@ func TestPrintTaskCommandsIfPresent(t *testing.T) {
}

func TestDoesNotPrintCommandIfMissing(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
task := &ast.Task{
Cmds: []*ast.Cmd{},
Expand All @@ -89,6 +99,8 @@ func TestDoesNotPrintCommandIfMissing(t *testing.T) {
}

func TestLayout(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
task := &ast.Task{
Task: "sample-task",
Expand Down Expand Up @@ -123,6 +135,8 @@ commands:
}

func TestPrintDescriptionAsFallback(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()
taskWithoutSummary := &ast.Task{
Desc: "description",
Expand Down Expand Up @@ -150,6 +164,8 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
}

func TestPrintAllWithSpaces(t *testing.T) {
t.Parallel()

buffer, l := createDummyLogger()

t1 := &ast.Task{Task: "t1"}
Expand Down
Loading
Loading