Skip to content

Commit 54430cb

Browse files
authored
Revert "lint: Enable paralleltest, fix issues (#1367)" (#1368)
The PR was merged prematurely. Maintainers are not yet in agreement about this change. This reverts commit 7b6c114.
1 parent 7b6c114 commit 54430cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+460
-1327
lines changed

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ linters:
1818

1919
# Our own extras:
2020
- gofumpt
21-
- nolintlint # lints nolint directives
22-
- paralleltest # requires t.Parallel on all tests
21+
- nolintlint # lints nolint directives
2322
- revive
2423

2524
linters-settings:

array_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ func BenchmarkBoolsReflect(b *testing.B) {
5353
}
5454

5555
func TestArrayWrappers(t *testing.T) {
56-
t.Parallel()
57-
5856
tests := []struct {
5957
desc string
6058
field Field
@@ -103,16 +101,11 @@ func TestArrayWrappers(t *testing.T) {
103101
}
104102

105103
for _, tt := range tests {
106-
tt := tt
107-
t.Run(tt.desc, func(t *testing.T) {
108-
t.Parallel()
109-
110-
enc := zapcore.NewMapObjectEncoder()
111-
tt.field.Key = "k"
112-
tt.field.AddTo(enc)
113-
assert.Equal(t, tt.expected, enc.Fields["k"], "unexpected map contents")
114-
assert.Equal(t, 1, len(enc.Fields), "found extra keys in map: %v", enc.Fields)
115-
})
104+
enc := zapcore.NewMapObjectEncoder()
105+
tt.field.Key = "k"
106+
tt.field.AddTo(enc)
107+
assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
108+
assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
116109
}
117110
}
118111

buffer/buffer_test.go

Lines changed: 16 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -30,86 +30,32 @@ import (
3030
)
3131

3232
func TestBufferWrites(t *testing.T) {
33-
t.Parallel()
33+
buf := NewPool().Get()
3434

3535
tests := []struct {
3636
desc string
37-
f func(*Buffer)
37+
f func()
3838
want string
3939
}{
40-
{
41-
desc: "AppendByte",
42-
f: func(buf *Buffer) { buf.AppendByte('v') },
43-
want: "v",
44-
},
45-
{
46-
desc: "AppendString",
47-
f: func(buf *Buffer) { buf.AppendString("foo") },
48-
want: "foo",
49-
},
50-
{
51-
desc: "AppendIntPositive",
52-
f: func(buf *Buffer) { buf.AppendInt(42) },
53-
want: "42",
54-
},
55-
{
56-
desc: "AppendIntNegative",
57-
f: func(buf *Buffer) { buf.AppendInt(-42) },
58-
want: "-42",
59-
},
60-
{
61-
desc: "AppendUint",
62-
f: func(buf *Buffer) { buf.AppendUint(42) },
63-
want: "42",
64-
},
65-
{
66-
desc: "AppendBool",
67-
f: func(buf *Buffer) { buf.AppendBool(true) },
68-
want: "true",
69-
},
70-
{
71-
desc: "AppendFloat64",
72-
f: func(buf *Buffer) { buf.AppendFloat(3.14, 64) },
73-
want: "3.14",
74-
},
40+
{"AppendByte", func() { buf.AppendByte('v') }, "v"},
41+
{"AppendString", func() { buf.AppendString("foo") }, "foo"},
42+
{"AppendIntPositive", func() { buf.AppendInt(42) }, "42"},
43+
{"AppendIntNegative", func() { buf.AppendInt(-42) }, "-42"},
44+
{"AppendUint", func() { buf.AppendUint(42) }, "42"},
45+
{"AppendBool", func() { buf.AppendBool(true) }, "true"},
46+
{"AppendFloat64", func() { buf.AppendFloat(3.14, 64) }, "3.14"},
7547
// Intentionally introduce some floating-point error.
76-
{
77-
desc: "AppendFloat32",
78-
f: func(buf *Buffer) { buf.AppendFloat(float64(float32(3.14)), 32) },
79-
want: "3.14",
80-
},
81-
{
82-
desc: "AppendWrite",
83-
f: func(buf *Buffer) { buf.Write([]byte("foo")) },
84-
want: "foo",
85-
},
86-
{
87-
desc: "AppendTime",
88-
f: func(buf *Buffer) { buf.AppendTime(time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC), time.RFC3339) },
89-
want: "2000-01-02T03:04:05Z",
90-
},
91-
{
92-
desc: "WriteByte",
93-
f: func(buf *Buffer) { buf.WriteByte('v') },
94-
want: "v",
95-
},
96-
{
97-
desc: "WriteString",
98-
f: func(buf *Buffer) { buf.WriteString("foo") },
99-
want: "foo",
100-
},
48+
{"AppendFloat32", func() { buf.AppendFloat(float64(float32(3.14)), 32) }, "3.14"},
49+
{"AppendWrite", func() { buf.Write([]byte("foo")) }, "foo"},
50+
{"AppendTime", func() { buf.AppendTime(time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC), time.RFC3339) }, "2000-01-02T03:04:05Z"},
51+
{"WriteByte", func() { buf.WriteByte('v') }, "v"},
52+
{"WriteString", func() { buf.WriteString("foo") }, "foo"},
10153
}
10254

103-
pool := NewPool()
10455
for _, tt := range tests {
105-
tt := tt
10656
t.Run(tt.desc, func(t *testing.T) {
107-
t.Parallel()
108-
109-
buf := pool.Get()
110-
defer buf.Free()
111-
112-
tt.f(buf)
57+
buf.Reset()
58+
tt.f()
11359
assert.Equal(t, tt.want, buf.String(), "Unexpected buffer.String().")
11460
assert.Equal(t, tt.want, string(buf.Bytes()), "Unexpected string(buffer.Bytes()).")
11561
assert.Equal(t, len(tt.want), buf.Len(), "Unexpected buffer length.")

buffer/pool_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828
)
2929

3030
func TestBuffers(t *testing.T) {
31-
t.Parallel()
32-
3331
const dummyData = "dummy data"
3432
p := NewPool()
3533

clock_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ func (c constantClock) NewTicker(d time.Duration) *time.Ticker {
3737
}
3838

3939
func TestWithClock(t *testing.T) {
40-
t.Parallel()
41-
4240
date := time.Date(2077, 1, 23, 10, 15, 13, 441, time.UTC)
4341
clock := constantClock(date)
4442
withLogger(t, DebugLevel, []Option{WithClock(clock)}, func(log *Logger, logs *observer.ObservedLogs) {

config_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
)
3333

3434
func TestConfig(t *testing.T) {
35-
t.Parallel()
36-
3735
tests := []struct {
3836
desc string
3937
cfg Config
@@ -59,10 +57,7 @@ func TestConfig(t *testing.T) {
5957
}
6058

6159
for _, tt := range tests {
62-
tt := tt
6360
t.Run(tt.desc, func(t *testing.T) {
64-
t.Parallel()
65-
6661
logOut := filepath.Join(t.TempDir(), "test.log")
6762

6863
tt.cfg.OutputPaths = []string{logOut}
@@ -91,8 +86,6 @@ func TestConfig(t *testing.T) {
9186
}
9287

9388
func TestConfigWithInvalidPaths(t *testing.T) {
94-
t.Parallel()
95-
9689
tests := []struct {
9790
desc string
9891
output string
@@ -104,10 +97,7 @@ func TestConfigWithInvalidPaths(t *testing.T) {
10497
}
10598

10699
for _, tt := range tests {
107-
tt := tt
108100
t.Run(tt.desc, func(t *testing.T) {
109-
t.Parallel()
110-
111101
cfg := NewProductionConfig()
112102
cfg.OutputPaths = []string{tt.output}
113103
cfg.ErrorOutputPaths = []string{tt.errOutput}
@@ -118,8 +108,6 @@ func TestConfigWithInvalidPaths(t *testing.T) {
118108
}
119109

120110
func TestConfigWithMissingAttributes(t *testing.T) {
121-
t.Parallel()
122-
123111
tests := []struct {
124112
desc string
125113
cfg Config
@@ -147,10 +135,7 @@ func TestConfigWithMissingAttributes(t *testing.T) {
147135
}
148136

149137
for _, tt := range tests {
150-
tt := tt
151138
t.Run(tt.desc, func(t *testing.T) {
152-
t.Parallel()
153-
154139
cfg := tt.cfg
155140
_, err := cfg.Build()
156141
assert.EqualError(t, err, tt.expectErr)
@@ -174,8 +159,6 @@ func makeSamplerCountingHook() (h func(zapcore.Entry, zapcore.SamplingDecision),
174159
}
175160

176161
func TestConfigWithSamplingHook(t *testing.T) {
177-
t.Parallel()
178-
179162
shook, dcount, scount := makeSamplerCountingHook()
180163
cfg := Config{
181164
Level: NewAtomicLevelAt(InfoLevel),

encoder_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,16 @@ import (
2929
)
3030

3131
func TestRegisterDefaultEncoders(t *testing.T) {
32-
t.Parallel()
33-
3432
testEncodersRegistered(t, "console", "json")
3533
}
3634

37-
//nolint:paralleltest // modifies global registry
3835
func TestRegisterEncoder(t *testing.T) {
3936
testEncoders(func() {
4037
assert.NoError(t, RegisterEncoder("foo", newNilEncoder), "expected to be able to register the encoder foo")
4138
testEncodersRegistered(t, "foo")
4239
})
4340
}
4441

45-
//nolint:paralleltest // modifies global registry
4642
func TestDuplicateRegisterEncoder(t *testing.T) {
4743
testEncoders(func() {
4844
assert.NoError(t, RegisterEncoder("foo", newNilEncoder), "expected to be able to register the encoder foo")
@@ -51,12 +47,9 @@ func TestDuplicateRegisterEncoder(t *testing.T) {
5147
}
5248

5349
func TestRegisterEncoderNoName(t *testing.T) {
54-
t.Parallel()
55-
5650
assert.Equal(t, errNoEncoderNameSpecified, RegisterEncoder("", newNilEncoder), "expected an error when registering an encoder with no name")
5751
}
5852

59-
//nolint:paralleltest // modifies global registry
6053
func TestNewEncoder(t *testing.T) {
6154
testEncoders(func() {
6255
assert.NoError(t, RegisterEncoder("foo", newNilEncoder), "expected to be able to register the encoder foo")
@@ -67,15 +60,11 @@ func TestNewEncoder(t *testing.T) {
6760
}
6861

6962
func TestNewEncoderNotRegistered(t *testing.T) {
70-
t.Parallel()
71-
7263
_, err := newEncoder("foo", zapcore.EncoderConfig{})
7364
assert.Error(t, err, "expected an error when trying to create an encoder of an unregistered name")
7465
}
7566

7667
func TestNewEncoderNoName(t *testing.T) {
77-
t.Parallel()
78-
7968
_, err := newEncoder("", zapcore.EncoderConfig{})
8069
assert.Equal(t, errNoEncoderNameSpecified, err, "expected an error when creating an encoder with no name")
8170
}

error_test.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
)
3333

3434
func TestErrorConstructors(t *testing.T) {
35-
t.Parallel()
36-
3735
fail := errors.New("fail")
3836

3937
tests := []struct {
@@ -50,21 +48,14 @@ func TestErrorConstructors(t *testing.T) {
5048
}
5149

5250
for _, tt := range tests {
53-
tt := tt
54-
t.Run(tt.name, func(t *testing.T) {
55-
t.Parallel()
56-
57-
if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
58-
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
59-
}
60-
assertCanBeReused(t, tt.field)
61-
})
51+
if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
52+
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
53+
}
54+
assertCanBeReused(t, tt.field)
6255
}
6356
}
6457

6558
func TestErrorArrayConstructor(t *testing.T) {
66-
t.Parallel()
67-
6859
tests := []struct {
6960
desc string
7061
field Field
@@ -79,22 +70,15 @@ func TestErrorArrayConstructor(t *testing.T) {
7970
}
8071

8172
for _, tt := range tests {
82-
tt := tt
83-
t.Run(tt.desc, func(t *testing.T) {
84-
t.Parallel()
85-
86-
enc := zapcore.NewMapObjectEncoder()
87-
tt.field.Key = "k"
88-
tt.field.AddTo(enc)
89-
assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
90-
assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
91-
})
73+
enc := zapcore.NewMapObjectEncoder()
74+
tt.field.Key = "k"
75+
tt.field.AddTo(enc)
76+
assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
77+
assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
9278
}
9379
}
9480

9581
func TestErrorsArraysHandleRichErrors(t *testing.T) {
96-
t.Parallel()
97-
9882
errs := []error{fmt.Errorf("egad")}
9983

10084
enc := zapcore.NewMapObjectEncoder()

exp/zapfield/zapfield_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ type (
3636
)
3737

3838
func TestFieldConstructors(t *testing.T) {
39-
t.Parallel()
40-
4139
var (
4240
key = MyKey("test key")
4341
value = MyValue("test value")
@@ -57,15 +55,10 @@ func TestFieldConstructors(t *testing.T) {
5755
}
5856

5957
for _, tt := range tests {
60-
tt := tt
61-
t.Run(tt.name, func(t *testing.T) {
62-
t.Parallel()
63-
64-
if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
65-
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
66-
}
67-
assertCanBeReused(t, tt.field)
68-
})
58+
if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
59+
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
60+
}
61+
assertCanBeReused(t, tt.field)
6962
}
7063
}
7164

0 commit comments

Comments
 (0)