Skip to content

Commit c100786

Browse files
committed
feat: make all viable tests parallel
Signed-off-by: Liam Stanley <liam@liam.sh>
1 parent d0a3beb commit c100786

5 files changed

Lines changed: 45 additions & 3 deletions

File tree

commands_test.go

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

88
func TestEvery(t *testing.T) {
9+
t.Parallel()
910
expected := "every ms"
1011
msg := Every(time.Millisecond, func(t time.Time) Msg {
1112
return expected
@@ -16,6 +17,7 @@ func TestEvery(t *testing.T) {
1617
}
1718

1819
func TestTick(t *testing.T) {
20+
t.Parallel()
1921
expected := "tick"
2022
msg := Tick(time.Millisecond, func(t time.Time) Msg {
2123
return expected
@@ -26,31 +28,37 @@ func TestTick(t *testing.T) {
2628
}
2729

2830
func TestBatch(t *testing.T) {
31+
t.Parallel()
2932
testMultipleCommands[BatchMsg](t, Batch)
3033
}
3134

3235
func TestSequence(t *testing.T) {
36+
t.Parallel()
3337
testMultipleCommands[sequenceMsg](t, Sequence)
3438
}
3539

3640
func testMultipleCommands[T ~[]Cmd](t *testing.T, createFn func(cmd ...Cmd) Cmd) {
3741
t.Run("nil cmd", func(t *testing.T) {
42+
t.Parallel()
3843
if b := createFn(nil); b != nil {
3944
t.Fatalf("expected nil, got %+v", b)
4045
}
4146
})
4247
t.Run("empty cmd", func(t *testing.T) {
48+
t.Parallel()
4349
if b := createFn(); b != nil {
4450
t.Fatalf("expected nil, got %+v", b)
4551
}
4652
})
4753
t.Run("single cmd", func(t *testing.T) {
54+
t.Parallel()
4855
b := createFn(Quit)()
4956
if _, ok := b.(QuitMsg); !ok {
5057
t.Fatalf("expected a QuitMsg, got %T", b)
5158
}
5259
})
5360
t.Run("mixed nil cmds", func(t *testing.T) {
61+
t.Parallel()
5462
b := createFn(nil, Quit, nil, Quit, nil, nil)()
5563
if l := len(b.(T)); l != 2 {
5664
t.Fatalf("expected a []Cmd with len 2, got %d", l)

exec_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func TestTeaExec(t *testing.T) {
9090

9191
for _, test := range tests {
9292
t.Run(test.name, func(t *testing.T) {
93+
t.Parallel()
9394
var buf bytes.Buffer
9495
var in bytes.Buffer
9596

@@ -118,6 +119,7 @@ func TestTeaExec(t *testing.T) {
118119
}
119120

120121
func TestTeaExecWithNilInput(t *testing.T) {
122+
t.Parallel()
121123
var buf bytes.Buffer
122124

123125
m := &testExecNoInputModel{}

options_test.go

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

1111
func TestOptions(t *testing.T) {
1212
t.Run("output", func(t *testing.T) {
13+
t.Parallel()
1314
var b bytes.Buffer
1415
p := NewProgram(nil, WithOutput(&b))
1516
if f, ok := p.output.(*os.File); ok {
@@ -18,27 +19,31 @@ func TestOptions(t *testing.T) {
1819
})
1920

2021
t.Run("renderer", func(t *testing.T) {
22+
t.Parallel()
2123
p := NewProgram(nil, WithoutRenderer())
2224
if !p.disableRenderer {
2325
t.Errorf("expected renderer to be a nilRenderer, got %v", p.renderer)
2426
}
2527
})
2628

2729
t.Run("without signals", func(t *testing.T) {
30+
t.Parallel()
2831
p := NewProgram(nil, WithoutSignals())
2932
if atomic.LoadUint32(&p.ignoreSignals) == 0 {
3033
t.Errorf("ignore signals should have been set")
3134
}
3235
})
3336

3437
t.Run("filter", func(t *testing.T) {
38+
t.Parallel()
3539
p := NewProgram(nil, WithFilter(func(_ Model, msg Msg) Msg { return msg }))
3640
if p.filter == nil {
3741
t.Errorf("expected filter to be set")
3842
}
3943
})
4044

4145
t.Run("external context", func(t *testing.T) {
46+
t.Parallel()
4247
extCtx, extCancel := context.WithCancel(context.Background())
4348
defer extCancel()
4449

@@ -55,6 +60,7 @@ func TestOptions(t *testing.T) {
5560
}
5661

5762
t.Run("nil input", func(t *testing.T) {
63+
t.Parallel()
5864
exercise(t, WithInput(nil), func(p *Program) {
5965
if !p.disableInput || p.input != nil {
6066
t.Errorf("expected input to be disabled, got %v", p.input)
@@ -63,6 +69,7 @@ func TestOptions(t *testing.T) {
6369
})
6470

6571
t.Run("custom input", func(t *testing.T) {
72+
t.Parallel()
6673
var b bytes.Buffer
6774
exercise(t, WithInput(&b), func(p *Program) {
6875
if p.input != &b {
@@ -79,6 +86,7 @@ func TestOptions(t *testing.T) {
7986
}
8087

8188
t.Run("without catch panics", func(t *testing.T) {
89+
t.Parallel()
8290
exercise(t, WithoutCatchPanics(), func(p *Program) {
8391
if !p.disableCatchPanics {
8492
t.Errorf("expected catch panics to be disabled")
@@ -87,6 +95,7 @@ func TestOptions(t *testing.T) {
8795
})
8896

8997
t.Run("without signal handler", func(t *testing.T) {
98+
t.Parallel()
9099
exercise(t, WithoutSignalHandler(), func(p *Program) {
91100
if !p.disableSignalHandler {
92101
t.Errorf("expected signal handler to be disabled")

screen_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func TestViewModel(t *testing.T) {
132132

133133
for _, test := range tests {
134134
t.Run(test.name, func(t *testing.T) {
135+
t.Parallel()
135136
var buf bytes.Buffer
136137
var in bytes.Buffer
137138

@@ -179,6 +180,7 @@ func TestClearMsg(t *testing.T) {
179180

180181
for _, test := range tests {
181182
t.Run(test.name, func(t *testing.T) {
183+
t.Parallel()
182184
var buf bytes.Buffer
183185
var in bytes.Buffer
184186

tea_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"errors"
7+
"fmt"
78
"io"
89
"strings"
910
"sync"
@@ -66,6 +67,7 @@ func (m *testModel) View() View {
6667
}
6768

6869
func TestTeaModel(t *testing.T) {
70+
t.Parallel()
6971
var buf bytes.Buffer
7072
var in bytes.Buffer
7173
in.Write([]byte("q"))
@@ -88,6 +90,7 @@ func TestTeaModel(t *testing.T) {
8890
}
8991

9092
func TestTeaQuit(t *testing.T) {
93+
t.Parallel()
9194
var buf bytes.Buffer
9295
var in bytes.Buffer
9396

@@ -112,6 +115,7 @@ func TestTeaQuit(t *testing.T) {
112115
}
113116

114117
func TestTeaWaitQuit(t *testing.T) {
118+
t.Parallel()
115119
var buf bytes.Buffer
116120
var in bytes.Buffer
117121

@@ -165,6 +169,7 @@ func TestTeaWaitQuit(t *testing.T) {
165169
}
166170

167171
func TestTeaWaitKill(t *testing.T) {
172+
t.Parallel()
168173
var buf bytes.Buffer
169174
var in bytes.Buffer
170175

@@ -218,9 +223,13 @@ func TestTeaWaitKill(t *testing.T) {
218223
}
219224

220225
func TestTeaWithFilter(t *testing.T) {
221-
testTeaWithFilter(t, 0)
222-
testTeaWithFilter(t, 1)
223-
testTeaWithFilter(t, 2)
226+
for _, preventCount := range []uint32{0, 1, 2} {
227+
preventCount := preventCount
228+
t.Run(fmt.Sprintf("prevent_%d", preventCount), func(t *testing.T) {
229+
t.Parallel()
230+
testTeaWithFilter(t, preventCount)
231+
})
232+
}
224233
}
225234

226235
func testTeaWithFilter(t *testing.T, preventCount uint32) {
@@ -260,6 +269,7 @@ func testTeaWithFilter(t *testing.T, preventCount uint32) {
260269
}
261270

262271
func TestTeaKill(t *testing.T) {
272+
t.Parallel()
263273
var buf bytes.Buffer
264274
var in bytes.Buffer
265275

@@ -292,6 +302,7 @@ func TestTeaKill(t *testing.T) {
292302
}
293303

294304
func TestTeaContext(t *testing.T) {
305+
t.Parallel()
295306
ctx, cancel := context.WithCancel(t.Context())
296307
var buf bytes.Buffer
297308
var in bytes.Buffer
@@ -325,6 +336,7 @@ func TestTeaContext(t *testing.T) {
325336
}
326337

327338
func TestTeaContextImplodeDeadlock(t *testing.T) {
339+
t.Parallel()
328340
ctx, cancel := context.WithCancel(t.Context())
329341
var buf bytes.Buffer
330342
var in bytes.Buffer
@@ -351,6 +363,7 @@ func TestTeaContextImplodeDeadlock(t *testing.T) {
351363
}
352364

353365
func TestTeaContextBatchDeadlock(t *testing.T) {
366+
t.Parallel()
354367
ctx, cancel := context.WithCancel(t.Context())
355368
var buf bytes.Buffer
356369
var in bytes.Buffer
@@ -386,6 +399,7 @@ func TestTeaContextBatchDeadlock(t *testing.T) {
386399
}
387400

388401
func TestTeaBatchMsg(t *testing.T) {
402+
t.Parallel()
389403
var buf bytes.Buffer
390404
var in bytes.Buffer
391405

@@ -421,6 +435,7 @@ func TestTeaBatchMsg(t *testing.T) {
421435
}
422436

423437
func TestTeaSequenceMsg(t *testing.T) {
438+
t.Parallel()
424439
var buf bytes.Buffer
425440
var in bytes.Buffer
426441

@@ -445,6 +460,7 @@ func TestTeaSequenceMsg(t *testing.T) {
445460
}
446461

447462
func TestTeaSequenceMsgWithBatchMsg(t *testing.T) {
463+
t.Parallel()
448464
var buf bytes.Buffer
449465
var in bytes.Buffer
450466

@@ -472,6 +488,7 @@ func TestTeaSequenceMsgWithBatchMsg(t *testing.T) {
472488
}
473489

474490
func TestTeaNestedSequenceMsg(t *testing.T) {
491+
t.Parallel()
475492
var buf bytes.Buffer
476493
var in bytes.Buffer
477494

@@ -496,6 +513,7 @@ func TestTeaNestedSequenceMsg(t *testing.T) {
496513
}
497514

498515
func TestTeaSend(t *testing.T) {
516+
t.Parallel()
499517
var buf bytes.Buffer
500518
var in bytes.Buffer
501519

@@ -517,6 +535,7 @@ func TestTeaSend(t *testing.T) {
517535
}
518536

519537
func TestTeaNoRun(t *testing.T) {
538+
t.Parallel()
520539
var buf bytes.Buffer
521540
var in bytes.Buffer
522541

@@ -528,6 +547,7 @@ func TestTeaNoRun(t *testing.T) {
528547
}
529548

530549
func TestTeaPanic(t *testing.T) {
550+
t.Parallel()
531551
var buf bytes.Buffer
532552
var in bytes.Buffer
533553

@@ -558,6 +578,7 @@ func TestTeaPanic(t *testing.T) {
558578
}
559579

560580
func TestTeaGoroutinePanic(t *testing.T) {
581+
t.Parallel()
561582
var buf bytes.Buffer
562583
var in bytes.Buffer
563584

0 commit comments

Comments
 (0)