Skip to content

Commit

Permalink
lint: Enable paralleltest, fix issues (#1367)
Browse files Browse the repository at this point in the history
Enable the paralleltest linter.
This linter checks that all tests and subtests call t.Parallel.

Fix all fixable issues reported by the linter.
For cases where a test cannot be run in parallel,
add a `//nolint:paralleltest` comment with an appropriate explanation.
For example:

    //nolint:paralleltest // modifies global state

Best reviewed by ignoring all whitespace changes.

<details>
<summary>Full list fixed issues</summary>

```
array_test.go:55:1: Function TestArrayWrappers missing the call to method parallel (paralleltest)
buffer/buffer_test.go:32:1: Function TestBufferWrites missing the call to method parallel (paralleltest)
buffer/buffer_test.go:55:2: Range statement for test TestBufferWrites missing the call to method parallel in test Run (paralleltest)
buffer/pool_test.go:30:1: Function TestBuffers missing the call to method parallel (paralleltest)
clock_test.go:39:1: Function TestWithClock missing the call to method parallel (paralleltest)
config_test.go:34:1: Function TestConfig missing the call to method parallel (paralleltest)
config_test.go:59:2: Range statement for test TestConfig missing the call to method parallel in test Run (paralleltest)
config_test.go:88:1: Function TestConfigWithInvalidPaths missing the call to method parallel (paralleltest)
config_test.go:99:2: Range statement for test TestConfigWithInvalidPaths missing the call to method parallel in test Run (paralleltest)
config_test.go:110:1: Function TestConfigWithMissingAttributes missing the call to method parallel (paralleltest)
config_test.go:137:2: Range statement for test TestConfigWithMissingAttributes missing the call to method parallel in test Run (paralleltest)
config_test.go:161:1: Function TestConfigWithSamplingHook missing the call to method parallel (paralleltest)
encoder_test.go:31:1: Function TestRegisterDefaultEncoders missing the call to method parallel (paralleltest)
encoder_test.go:35:1: Function TestRegisterEncoder missing the call to method parallel (paralleltest)
encoder_test.go:42:1: Function TestDuplicateRegisterEncoder missing the call to method parallel (paralleltest)
encoder_test.go:49:1: Function TestRegisterEncoderNoName missing the call to method parallel (paralleltest)
encoder_test.go:53:1: Function TestNewEncoder missing the call to method parallel (paralleltest)
encoder_test.go:62:1: Function TestNewEncoderNotRegistered missing the call to method parallel (paralleltest)
encoder_test.go:67:1: Function TestNewEncoderNoName missing the call to method parallel (paralleltest)
error_test.go:34:1: Function TestErrorConstructors missing the call to method parallel (paralleltest)
error_test.go:58:1: Function TestErrorArrayConstructor missing the call to method parallel (paralleltest)
error_test.go:81:1: Function TestErrorsArraysHandleRichErrors missing the call to method parallel (paralleltest)
field_test.go:63:1: Function TestFieldConstructors missing the call to method parallel (paralleltest)
field_test.go:258:2: Range statement for test TestFieldConstructors missing the call to method parallel in test Run (paralleltest)
field_test.go:268:1: Function TestStackField missing the call to method parallel (paralleltest)
field_test.go:277:1: Function TestStackSkipField missing the call to method parallel (paralleltest)
field_test.go:286:1: Function TestStackSkipFieldWithSkip missing the call to method parallel (paralleltest)
field_test.go:294:1: Function TestDict missing the call to method parallel (paralleltest)
field_test.go:305:2: Range statement for test TestDict missing the call to method parallel in test Run (paralleltest)
flag_test.go:68:1: Function TestLevelFlag missing the call to method parallel (paralleltest)
flag_test.go:90:1: Function TestLevelFlagsAreIndependent missing the call to method parallel (paralleltest)
global_test.go:40:1: Function TestReplaceGlobals missing the call to method parallel (paralleltest)
global_test.go:69:1: Function TestGlobalsConcurrentUse missing the call to method parallel (paralleltest)
global_test.go:100:1: Function TestNewStdLog missing the call to method parallel (paralleltest)
global_test.go:108:1: Function TestNewStdLogAt missing the call to method parallel (paralleltest)
global_test.go:121:1: Function TestNewStdLogAtPanics missing the call to method parallel (paralleltest)
global_test.go:134:1: Function TestNewStdLogAtFatal missing the call to method parallel (paralleltest)
global_test.go:147:1: Function TestNewStdLogAtInvalid missing the call to method parallel (paralleltest)
global_test.go:152:1: Function TestRedirectStdLog missing the call to method parallel (paralleltest)
global_test.go:170:1: Function TestRedirectStdLogCaller missing the call to method parallel (paralleltest)
global_test.go:180:1: Function TestRedirectStdLogAt missing the call to method parallel (paralleltest)
global_test.go:204:1: Function TestRedirectStdLogAtCaller missing the call to method parallel (paralleltest)
global_test.go:220:1: Function TestRedirectStdLogAtPanics missing the call to method parallel (paralleltest)
global_test.go:240:1: Function TestRedirectStdLogAtFatal missing the call to method parallel (paralleltest)
global_test.go:260:1: Function TestRedirectStdLogAtInvalid missing the call to method parallel (paralleltest)
http_handler_test.go:38:1: Function TestAtomicLevelServeHTTP missing the call to method parallel (paralleltest)
http_handler_test.go:155:2: Range statement for test TestAtomicLevelServeHTTP missing the call to method parallel in test Run (paralleltest)
increase_level_test.go:42:1: Function TestIncreaseLevelTryDecrease missing the call to method parallel (paralleltest)
increase_level_test.go:68:1: Function TestIncreaseLevel missing the call to method parallel (paralleltest)
internal/color/color_test.go:29:1: Function TestColorFormatting missing the call to method parallel (paralleltest)
internal/exit/exit_test.go:30:1: Function TestStub missing the call to method parallel (paralleltest)
internal/pool/pool_test.go:36:1: Function TestNew missing the call to method parallel (paralleltest)
internal/pool/pool_test.go:78:1: Function TestNew_Race missing the call to method parallel (paralleltest)
internal/stacktrace/stack_test.go:32:1: Function TestTake missing the call to method parallel (paralleltest)
internal/stacktrace/stack_test.go:44:1: Function TestTakeWithSkip missing the call to method parallel (paralleltest)
internal/stacktrace/stack_test.go:56:1: Function TestTakeWithSkipInnerFunc missing the call to method parallel (paralleltest)
internal/stacktrace/stack_test.go:71:1: Function TestTakeDeepStack missing the call to method parallel (paralleltest)
internal/ztest/clock_test.go:31:1: Function TestMockClock_NewTicker missing the call to method parallel (paralleltest)
internal/ztest/clock_test.go:59:1: Function TestMockClock_NewTicker_slowConsumer missing the call to method parallel (paralleltest)
internal/ztest/clock_test.go:77:1: Function TestMockClock_Add_negative missing the call to method parallel (paralleltest)
level_test.go:33:1: Function TestLevelEnablerFunc missing the call to method parallel (paralleltest)
level_test.go:52:1: Function TestNewAtomicLevel missing the call to method parallel (paralleltest)
level_test.go:61:1: Function TestParseAtomicLevel missing the call to method parallel (paralleltest)
level_test.go:83:1: Function TestAtomicLevelMutation missing the call to method parallel (paralleltest)
level_test.go:101:1: Function TestAtomicLevelText missing the call to method parallel (paralleltest)
logger_test.go:49:1: Function TestLoggerAtomicLevel missing the call to method parallel (paralleltest)
logger_test.go:88:1: Function TestLoggerLevel missing the call to method parallel (paralleltest)
logger_test.go:115:1: Function TestLoggerInitialFields missing the call to method parallel (paralleltest)
logger_test.go:128:1: Function TestLoggerWith missing the call to method parallel (paralleltest)
logger_test.go:155:2: Range statement for test TestLoggerWith missing the call to method parallel in test Run (paralleltest)
logger_test.go:178:1: Function TestLoggerWithCaptures missing the call to method parallel (paralleltest)
logger_test.go:339:2: Range statement for test TestLoggerWithCaptures missing the call to method parallel in test Run (paralleltest)
logger_test.go:375:1: Function TestLoggerLogPanic missing the call to method parallel (paralleltest)
logger_test.go:405:1: Function TestLoggerLogFatal missing the call to method parallel (paralleltest)
logger_test.go:432:1: Function TestLoggerLeveledMethods missing the call to method parallel (paralleltest)
logger_test.go:458:1: Function TestLoggerLogLevels missing the call to method parallel (paralleltest)
logger_test.go:481:1: Function TestLoggerAlwaysPanics missing the call to method parallel (paralleltest)
logger_test.go:497:1: Function TestLoggerAlwaysFatals missing the call to method parallel (paralleltest)
logger_test.go:518:1: Function TestLoggerDPanic missing the call to method parallel (paralleltest)
logger_test.go:539:1: Function TestLoggerNoOpsDisabledLevels missing the call to method parallel (paralleltest)
logger_test.go:551:1: Function TestLoggerNames missing the call to method parallel (paralleltest)
logger_test.go:590:1: Function TestLoggerWriteFailure missing the call to method parallel (paralleltest)
logger_test.go:607:1: Function TestLoggerSync missing the call to method parallel (paralleltest)
logger_test.go:614:1: Function TestLoggerSyncFail missing the call to method parallel (paralleltest)
logger_test.go:627:1: Function TestLoggerAddCaller missing the call to method parallel (paralleltest)
logger_test.go:659:1: Function TestLoggerAddCallerFunction missing the call to method parallel (paralleltest)
logger_test.go:739:1: Function TestLoggerAddCallerFail missing the call to method parallel (paralleltest)
logger_test.go:762:1: Function TestLoggerReplaceCore missing the call to method parallel (paralleltest)
logger_test.go:774:1: Function TestLoggerIncreaseLevel missing the call to method parallel (paralleltest)
logger_test.go:789:1: Function TestLoggerHooks missing the call to method parallel (paralleltest)
logger_test.go:798:1: Function TestLoggerConcurrent missing the call to method parallel (paralleltest)
logger_test.go:828:1: Function TestLoggerFatalOnNoop missing the call to method parallel (paralleltest)
logger_test.go:839:1: Function TestLoggerCustomOnFatal missing the call to method parallel (paralleltest)
logger_test.go:857:2: Range statement for test TestLoggerCustomOnFatal missing the call to method parallel in test Run (paralleltest)
logger_test.go:891:1: Function TestLoggerWithFatalHook missing the call to method parallel (paralleltest)
logger_test.go:900:1: Function TestNopLogger missing the call to method parallel (paralleltest)
logger_test.go:903:2: Function TestNopLogger missing the call to method parallel in the test run (paralleltest)
logger_test.go:910:2: Function TestNopLogger missing the call to method parallel in the test run (paralleltest)
logger_test.go:914:2: Function TestNopLogger missing the call to method parallel in the test run (paralleltest)
logger_test.go:921:1: Function TestMust missing the call to method parallel (paralleltest)
logger_test.go:922:2: Function TestMust missing the call to method parallel in the test run (paralleltest)
logger_test.go:926:2: Function TestMust missing the call to method parallel in the test run (paralleltest)
sink_test.go:47:1: Function TestRegisterSink missing the call to method parallel (paralleltest)
sink_test.go:86:1: Function TestRegisterSinkErrors missing the call to method parallel (paralleltest)
sink_test.go:100:2: Range statement for test TestRegisterSinkErrors missing the call to method parallel in test Run (paralleltest)
stacktrace_ext_test.go:49:1: Function TestStacktraceFiltersZapLog missing the call to method parallel (paralleltest)
stacktrace_ext_test.go:59:1: Function TestStacktraceFiltersZapMarshal missing the call to method parallel (paralleltest)
stacktrace_ext_test.go:86:1: Function TestStacktraceFiltersVendorZap missing the call to method parallel (paralleltest)
stacktrace_ext_test.go:122:1: Function TestStacktraceWithoutCallerSkip missing the call to method parallel (paralleltest)
stacktrace_ext_test.go:133:1: Function TestStacktraceWithCallerSkip missing the call to method parallel (paralleltest)
sugar_test.go:36:1: Function TestSugarWith missing the call to method parallel (paralleltest)
sugar_test.go:187:1: Function TestSugarFieldsInvalidPairs missing the call to method parallel (paralleltest)
sugar_test.go:207:1: Function TestSugarStructuredLogging missing the call to method parallel (paralleltest)
sugar_test.go:244:1: Function TestSugarConcatenatingLogging missing the call to method parallel (paralleltest)
sugar_test.go:276:1: Function TestSugarTemplatedLogging missing the call to method parallel (paralleltest)
sugar_test.go:312:1: Function TestSugarLnLogging missing the call to method parallel (paralleltest)
sugar_test.go:348:1: Function TestSugarLnLoggingIgnored missing the call to method parallel (paralleltest)
sugar_test.go:355:1: Function TestSugarPanicLogging missing the call to method parallel (paralleltest)
sugar_test.go:390:1: Function TestSugarFatalLogging missing the call to method parallel (paralleltest)
sugar_test.go:426:1: Function TestSugarAddCaller missing the call to method parallel (paralleltest)
sugar_test.go:451:1: Function TestSugarAddCallerFail missing the call to method parallel (paralleltest)
sugar_test.go:469:1: Function TestSugarWithOptionsIncreaseLevel missing the call to method parallel (paralleltest)
sugar_test.go:485:1: Function TestSugarLnWithOptionsIncreaseLevel missing the call to method parallel (paralleltest)
time_test.go:30:1: Function TestTimeToMillis missing the call to method parallel (paralleltest)
writer_test.go:38:1: Function TestOpenNoPaths missing the call to method parallel (paralleltest)
writer_test.go:51:1: Function TestOpen missing the call to method parallel (paralleltest)
writer_test.go:82:2: Range statement for test TestOpen missing the call to method parallel in test Run (paralleltest)
writer_test.go:96:1: Function TestOpenPathsNotFound missing the call to method parallel (paralleltest)
writer_test.go:124:2: Range statement for test TestOpenPathsNotFound missing the call to method parallel in test Run (paralleltest)
writer_test.go:142:1: Function TestOpenRelativePath missing the call to method parallel (paralleltest)
writer_test.go:162:1: Function TestOpenFails missing the call to method parallel (paralleltest)
writer_test.go:179:1: Function TestOpenOtherErrors missing the call to method parallel (paralleltest)
writer_test.go:214:2: Range statement for test TestOpenOtherErrors missing the call to method parallel in test Run (paralleltest)
writer_test.go:241:1: Function TestOpenWithErroringSinkFactory missing the call to method parallel (paralleltest)
writer_test.go:254:1: Function TestCombineWriteSyncers missing the call to method parallel (paralleltest)
zapcore/buffered_write_syncer_test.go:33:1: Function TestBufferWriter missing the call to method parallel (paralleltest)
zapcore/buffered_write_syncer_test.go:36:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:47:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:56:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:64:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:77:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:88:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:99:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:109:2: Function TestBufferWriter missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:130:1: Function TestBufferWriterWithoutStart missing the call to method parallel (paralleltest)
zapcore/buffered_write_syncer_test.go:131:2: Function TestBufferWriterWithoutStart missing the call to method parallel in the test run (paralleltest)
zapcore/buffered_write_syncer_test.go:136:2: Function TestBufferWriterWithoutStart missing the call to method parallel in the test run (paralleltest)
zapcore/clock_test.go:33:1: Function TestSystemClock_NewTicker missing the call to method parallel (paralleltest)
zapcore/console_encoder_test.go:38:1: Function TestConsoleSeparator missing the call to method parallel (paralleltest)
zapcore/console_encoder_test.go:66:2: Range statement for test TestConsoleSeparator missing the call to method parallel in test Run (paralleltest)
zapcore/core_test.go:40:1: Function TestNopCore missing the call to method parallel (paralleltest)
zapcore/core_test.go:69:1: Function TestIOCore missing the call to method parallel (paralleltest)
zapcore/core_test.go:110:1: Function TestIOCoreSyncFail missing the call to method parallel (paralleltest)
zapcore/core_test.go:129:1: Function TestIOCoreSyncsOutput missing the call to method parallel (paralleltest)
zapcore/core_test.go:156:1: Function TestIOCoreWriteFailure missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:77:1: Function TestEncoderConfiguration missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:563:1: Function TestLevelEncoders missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:586:1: Function TestTimeEncoders missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:618:1: Function TestTimeEncodersWrongYAML missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:629:1: Function TestTimeEncodersParseFromJSON missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:652:1: Function TestDurationEncoders missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:677:1: Function TestCallerEncoders missing the call to method parallel (paralleltest)
zapcore/encoder_test.go:701:1: Function TestNameEncoders missing the call to method parallel (paralleltest)
zapcore/entry_test.go:48:1: Function TestPutNilEntry missing the call to method parallel (paralleltest)
zapcore/entry_test.go:76:1: Function TestEntryCaller missing the call to method parallel (paralleltest)
zapcore/entry_test.go:106:1: Function TestCheckedEntryWrite missing the call to method parallel (paralleltest)
zapcore/entry_test.go:107:2: Function TestCheckedEntryWrite missing the call to method parallel in the test run (paralleltest)
zapcore/entry_test.go:112:2: Function TestCheckedEntryWrite missing the call to method parallel in the test run (paralleltest)
zapcore/entry_test.go:118:2: Function TestCheckedEntryWrite missing the call to method parallel in the test run (paralleltest)
zapcore/entry_test.go:124:2: Function TestCheckedEntryWrite missing the call to method parallel in the test run (paralleltest)
zapcore/entry_test.go:134:2: Function TestCheckedEntryWrite missing the call to method parallel in the test run (paralleltest)
zapcore/error_test.go:67:1: Function TestErrorEncoding missing the call to method parallel (paralleltest)
zapcore/error_test.go:155:1: Function TestRichErrorSupport missing the call to method parallel (paralleltest)
zapcore/field_test.go:96:1: Function TestUnknownFieldType missing the call to method parallel (paralleltest)
zapcore/field_test.go:104:1: Function TestFieldAddingError missing the call to method parallel (paralleltest)
zapcore/field_test.go:130:1: Function TestFields missing the call to method parallel (paralleltest)
zapcore/field_test.go:183:1: Function TestInlineMarshaler missing the call to method parallel (paralleltest)
zapcore/field_test.go:204:1: Function TestEquals missing the call to method parallel (paralleltest)
zapcore/hook_test.go:33:1: Function TestHooks missing the call to method parallel (paralleltest)
zapcore/hook_test.go:44:2: Range statement for test TestHooks missing the call to method parallel in test Run (paralleltest)
zapcore/increase_level_test.go:34:1: Function TestIncreaseLevel missing the call to method parallel (paralleltest)
zapcore/increase_level_test.go:80:2: Range statement for test TestIncreaseLevel missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_impl_test.go:47:1: Function TestJSONClone missing the call to method parallel (paralleltest)
zapcore/json_encoder_impl_test.go:60:1: Function TestJSONEscaping missing the call to method parallel (paralleltest)
zapcore/json_encoder_impl_test.go:95:2: Function TestJSONEscaping missing the call to method parallel in the test run (paralleltest)
zapcore/json_encoder_impl_test.go:103:2: Function TestJSONEscaping missing the call to method parallel in the test run (paralleltest)
zapcore/json_encoder_impl_test.go:112:1: Function TestJSONEncoderObjectFields missing the call to method parallel (paralleltest)
zapcore/json_encoder_impl_test.go:284:2: Range statement for test TestJSONEncoderObjectFields missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_impl_test.go:291:1: Function TestJSONEncoderTimeFormats missing the call to method parallel (paralleltest)
zapcore/json_encoder_impl_test.go:333:2: Range statement for test TestJSONEncoderTimeFormats missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_impl_test.go:340:1: Function TestJSONEncoderArrays missing the call to method parallel (paralleltest)
zapcore/json_encoder_impl_test.go:442:2: Range statement for test TestJSONEncoderArrays missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_impl_test.go:459:1: Function TestJSONEncoderTimeArrays missing the call to method parallel (paralleltest)
zapcore/json_encoder_impl_test.go:493:2: Range statement for test TestJSONEncoderTimeArrays missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_impl_test.go:655:1: Function TestJSONQuick missing the call to method parallel (paralleltest)
zapcore/json_encoder_test.go:39:1: Function TestJSONEncodeEntry missing the call to method parallel (paralleltest)
zapcore/json_encoder_test.go:128:2: Range statement for test TestJSONEncodeEntry missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_test.go:139:1: Function TestNoEncodeLevelSupplied missing the call to method parallel (paralleltest)
zapcore/json_encoder_test.go:168:1: Function TestJSONEmptyConfig missing the call to method parallel (paralleltest)
zapcore/json_encoder_test.go:186:2: Range statement for test TestJSONEmptyConfig missing the call to method parallel in test Run (paralleltest)
zapcore/json_encoder_test.go:215:1: Function TestJSONCustomReflectedEncoder missing the call to method parallel (paralleltest)
zapcore/lazy_with_test.go:60:1: Function TestLazyCore missing the call to method parallel (paralleltest)
zapcore/lazy_with_test.go:122:2: Range statement for test TestLazyCore missing the call to method parallel in test Run (paralleltest)
zapcore/level_strings_test.go:29:1: Function TestAllLevelsCoveredByLevelString missing the call to method parallel (paralleltest)
zapcore/level_test.go:32:1: Function TestLevelString missing the call to method parallel (paralleltest)
zapcore/level_test.go:51:1: Function TestLevelText missing the call to method parallel (paralleltest)
zapcore/level_test.go:80:1: Function TestParseLevel missing the call to method parallel (paralleltest)
zapcore/level_test.go:101:1: Function TestCapitalLevelsParse missing the call to method parallel (paralleltest)
zapcore/level_test.go:122:1: Function TestWeirdLevelsParse missing the call to method parallel (paralleltest)
zapcore/level_test.go:153:1: Function TestLevelNils missing the call to method parallel (paralleltest)
zapcore/level_test.go:169:1: Function TestLevelUnmarshalUnknownText missing the call to method parallel (paralleltest)
zapcore/level_test.go:175:1: Function TestLevelAsFlagValue missing the call to method parallel (paralleltest)
zapcore/level_test.go:215:1: Function TestLevelOf missing the call to method parallel (paralleltest)
zapcore/memory_encoder_test.go:31:1: Function TestMapObjectEncoderAdd missing the call to method parallel (paralleltest)
zapcore/memory_encoder_test.go:250:2: Range statement for test TestMapObjectEncoderAdd missing the call to method parallel in test Run (paralleltest)
zapcore/memory_encoder_test.go:259:1: Function TestSliceArrayEncoderAppend missing the call to method parallel (paralleltest)
zapcore/memory_encoder_test.go:345:2: Range statement for test TestSliceArrayEncoderAppend missing the call to method parallel in test Run (paralleltest)
zapcore/memory_encoder_test.go:361:1: Function TestMapObjectEncoderReflectionFailures missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:69:1: Function TestSampler missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:91:1: Function TestLevelOfSampler missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:104:1: Function TestSamplerDisabledLevels missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:113:1: Function TestSamplerTicking missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:169:1: Function TestSamplerConcurrent missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:250:1: Function TestSamplerRaces missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:271:1: Function TestSamplerUnknownLevels missing the call to method parallel (paralleltest)
zapcore/sampler_test.go:278:2: Range statement for test TestSamplerUnknownLevels missing the call to method parallel in test Run (paralleltest)
zapcore/sampler_test.go:291:1: Function TestSamplerWithZeroThereafter missing the call to method parallel (paralleltest)
zapcore/tee_test.go:41:1: Function TestTeeUnusualInput missing the call to method parallel (paralleltest)
zapcore/tee_test.go:43:2: Function TestTeeUnusualInput missing the call to method parallel in the test run (paralleltest)
zapcore/tee_test.go:47:2: Function TestTeeUnusualInput missing the call to method parallel in the test run (paralleltest)
zapcore/tee_test.go:52:1: Function TestLevelOfTee missing the call to method parallel (paralleltest)
zapcore/tee_test.go:90:1: Function TestTeeCheck missing the call to method parallel (paralleltest)
zapcore/tee_test.go:116:1: Function TestTeeWrite missing the call to method parallel (paralleltest)
zapcore/tee_test.go:135:1: Function TestTeeWith missing the call to method parallel (paralleltest)
zapcore/tee_test.go:152:1: Function TestTeeEnabled missing the call to method parallel (paralleltest)
zapcore/tee_test.go:174:1: Function TestTeeSync missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:45:1: Function TestAddSyncWriteSyncer missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:58:1: Function TestAddSyncWriter missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:67:1: Function TestNewMultiWriteSyncerWorksForSingleWriter missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:77:1: Function TestMultiWriteSyncerWritesBoth missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:91:1: Function TestMultiWriteSyncerFailsWrite missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:97:1: Function TestMultiWriteSyncerFailsShortWrite missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:104:1: Function TestWritestoAllSyncs_EvenIfFirstErrors missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:114:1: Function TestMultiWriteSyncerSync_PropagatesErrors missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:122:1: Function TestMultiWriteSyncerSync_NoErrorsOnDiscard missing the call to method parallel (paralleltest)
zapcore/write_syncer_test.go:127:1: Function TestMultiWriteSyncerSync_AllCalled missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:34:1: Function TestLoggerInfoExpected missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:68:1: Function TestLoggerDebugExpected missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:88:1: Function TestLoggerDebugSuppressed missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:98:1: Function TestLoggerWarningExpected missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:118:1: Function TestLoggerErrorExpected missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:138:1: Function TestLoggerFatalExpected missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:158:1: Function TestLoggerV missing the call to method parallel (paralleltest)
zapgrpc/zapgrpc_test.go:200:2: Range statement for test TestLoggerV missing the call to method parallel in test Run (paralleltest)
zapio/writer_test.go:173:2: Function TestWrite_Sync missing the call to method parallel in the test run (paralleltest)
zapio/writer_test.go:177:2: Function TestWrite_Sync missing the call to method parallel in the test run (paralleltest)
zapio/writer_test.go:187:2: Function TestWrite_Sync missing the call to method parallel in the test run (paralleltest)
zaptest/logger_test.go:37:1: Function TestTestLogger missing the call to method parallel (paralleltest)
zaptest/logger_test.go:61:1: Function TestTestLoggerSupportsLevels missing the call to method parallel (paralleltest)
zaptest/logger_test.go:83:1: Function TestTestLoggerSupportsWrappedZapOptions missing the call to method parallel (paralleltest)
zaptest/logger_test.go:107:1: Function TestTestingWriter missing the call to method parallel (paralleltest)
zaptest/logger_test.go:116:1: Function TestTestLoggerErrorOutput missing the call to method parallel (paralleltest)
zaptest/observer/logged_entry_test.go:32:1: Function TestLoggedEntryContextMap missing the call to method parallel (paralleltest)
zaptest/observer/logged_entry_test.go:80:2: Range statement for test TestLoggedEntryContextMap missing the call to method parallel in test Run (paralleltest)
zaptest/observer/observer_test.go:40:1: Function TestObserver missing the call to method parallel (paralleltest)
zaptest/observer/observer_test.go:74:1: Function TestObserverWith missing the call to method parallel (paralleltest)
zaptest/observer/observer_test.go:126:1: Function TestFilters missing the call to method parallel (paralleltest)
zaptest/timeout_test.go:31:1: Function TestTimeout missing the call to method parallel (paralleltest)
zaptest/timeout_test.go:36:1: Function TestSleep missing the call to method parallel (paralleltest)
zaptest/writer_test.go:30:1: Function TestSyncer missing the call to method parallel (paralleltest)
zaptest/writer_test.go:38:1: Function TestDiscarder missing the call to method parallel (paralleltest)
zaptest/writer_test.go:46:1: Function TestFailWriter missing the call to method parallel (paralleltest)
zaptest/writer_test.go:54:1: Function TestShortWriter missing the call to method parallel (paralleltest)
zaptest/writer_test.go:62:1: Function TestBuffer missing the call to method parallel (paralleltest)
exp/zapfield/zapfield_test.go:38:1: Function TestFieldConstructors missing the call to method parallel (paralleltest)
exp/zapslog/handler_test.go:53:1: Function TestAddStack missing the call to method parallel (paralleltest)
exp/zapslog/handler_test.go:73:1: Function TestAddStackSkip missing the call to method parallel (paralleltest)
exp/zapslog/handler_test.go:93:2: Function TestEmptyAttr missing the call to method parallel in the test run (paralleltest)
exp/zapslog/handler_test.go:107:2: Function TestEmptyAttr missing the call to method parallel in the test run (paralleltest)
exp/zapslog/handler_test.go:117:2: Function TestEmptyAttr missing the call to method parallel in the test run (paralleltest)
exp/zapslog/handler_test.go:133:2: Function TestWithName missing the call to method parallel in the test run (paralleltest)
exp/zapslog/handler_test.go:142:2: Function TestWithName missing the call to method parallel in the test run (paralleltest)
exp/zapslog/handler_test.go:159:1: Function TestAttrKinds missing the call to method parallel (paralleltest)
zapgrpc/internal/test/grpc_test.go:35:1: Function TestLoggerV2 missing the call to method parallel (paralleltest)
```

</details>
  • Loading branch information
abhinav committed Oct 1, 2023
1 parent ed7ddb5 commit 7b6c114
Show file tree
Hide file tree
Showing 54 changed files with 1,327 additions and 460 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ linters:

# Our own extras:
- gofumpt
- nolintlint # lints nolint directives
- nolintlint # lints nolint directives
- paralleltest # requires t.Parallel on all tests
- revive

linters-settings:
Expand Down
17 changes: 12 additions & 5 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func BenchmarkBoolsReflect(b *testing.B) {
}

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

tests := []struct {
desc string
field Field
Expand Down Expand Up @@ -101,11 +103,16 @@ func TestArrayWrappers(t *testing.T) {
}

for _, tt := range tests {
enc := zapcore.NewMapObjectEncoder()
tt.field.Key = "k"
tt.field.AddTo(enc)
assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
tt := tt
t.Run(tt.desc, func(t *testing.T) {
t.Parallel()

enc := zapcore.NewMapObjectEncoder()
tt.field.Key = "k"
tt.field.AddTo(enc)
assert.Equal(t, tt.expected, enc.Fields["k"], "unexpected map contents")
assert.Equal(t, 1, len(enc.Fields), "found extra keys in map: %v", enc.Fields)
})
}
}

Expand Down
86 changes: 70 additions & 16 deletions buffer/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,86 @@ import (
)

func TestBufferWrites(t *testing.T) {
buf := NewPool().Get()
t.Parallel()

tests := []struct {
desc string
f func()
f func(*Buffer)
want string
}{
{"AppendByte", func() { buf.AppendByte('v') }, "v"},
{"AppendString", func() { buf.AppendString("foo") }, "foo"},
{"AppendIntPositive", func() { buf.AppendInt(42) }, "42"},
{"AppendIntNegative", func() { buf.AppendInt(-42) }, "-42"},
{"AppendUint", func() { buf.AppendUint(42) }, "42"},
{"AppendBool", func() { buf.AppendBool(true) }, "true"},
{"AppendFloat64", func() { buf.AppendFloat(3.14, 64) }, "3.14"},
{
desc: "AppendByte",
f: func(buf *Buffer) { buf.AppendByte('v') },
want: "v",
},
{
desc: "AppendString",
f: func(buf *Buffer) { buf.AppendString("foo") },
want: "foo",
},
{
desc: "AppendIntPositive",
f: func(buf *Buffer) { buf.AppendInt(42) },
want: "42",
},
{
desc: "AppendIntNegative",
f: func(buf *Buffer) { buf.AppendInt(-42) },
want: "-42",
},
{
desc: "AppendUint",
f: func(buf *Buffer) { buf.AppendUint(42) },
want: "42",
},
{
desc: "AppendBool",
f: func(buf *Buffer) { buf.AppendBool(true) },
want: "true",
},
{
desc: "AppendFloat64",
f: func(buf *Buffer) { buf.AppendFloat(3.14, 64) },
want: "3.14",
},
// Intentionally introduce some floating-point error.
{"AppendFloat32", func() { buf.AppendFloat(float64(float32(3.14)), 32) }, "3.14"},
{"AppendWrite", func() { buf.Write([]byte("foo")) }, "foo"},
{"AppendTime", func() { buf.AppendTime(time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC), time.RFC3339) }, "2000-01-02T03:04:05Z"},
{"WriteByte", func() { buf.WriteByte('v') }, "v"},
{"WriteString", func() { buf.WriteString("foo") }, "foo"},
{
desc: "AppendFloat32",
f: func(buf *Buffer) { buf.AppendFloat(float64(float32(3.14)), 32) },
want: "3.14",
},
{
desc: "AppendWrite",
f: func(buf *Buffer) { buf.Write([]byte("foo")) },
want: "foo",
},
{
desc: "AppendTime",
f: func(buf *Buffer) { buf.AppendTime(time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC), time.RFC3339) },
want: "2000-01-02T03:04:05Z",
},
{
desc: "WriteByte",
f: func(buf *Buffer) { buf.WriteByte('v') },
want: "v",
},
{
desc: "WriteString",
f: func(buf *Buffer) { buf.WriteString("foo") },
want: "foo",
},
}

pool := NewPool()
for _, tt := range tests {
tt := tt
t.Run(tt.desc, func(t *testing.T) {
buf.Reset()
tt.f()
t.Parallel()

buf := pool.Get()
defer buf.Free()

tt.f(buf)
assert.Equal(t, tt.want, buf.String(), "Unexpected buffer.String().")
assert.Equal(t, tt.want, string(buf.Bytes()), "Unexpected string(buffer.Bytes()).")
assert.Equal(t, len(tt.want), buf.Len(), "Unexpected buffer length.")
Expand Down
2 changes: 2 additions & 0 deletions buffer/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

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

const dummyData = "dummy data"
p := NewPool()

Expand Down
2 changes: 2 additions & 0 deletions clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (c constantClock) NewTicker(d time.Duration) *time.Ticker {
}

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

date := time.Date(2077, 1, 23, 10, 15, 13, 441, time.UTC)
clock := constantClock(date)
withLogger(t, DebugLevel, []Option{WithClock(clock)}, func(log *Logger, logs *observer.ObservedLogs) {
Expand Down
17 changes: 17 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

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

tests := []struct {
desc string
cfg Config
Expand All @@ -57,7 +59,10 @@ func TestConfig(t *testing.T) {
}

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

logOut := filepath.Join(t.TempDir(), "test.log")

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

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

tests := []struct {
desc string
output string
Expand All @@ -97,7 +104,10 @@ func TestConfigWithInvalidPaths(t *testing.T) {
}

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

cfg := NewProductionConfig()
cfg.OutputPaths = []string{tt.output}
cfg.ErrorOutputPaths = []string{tt.errOutput}
Expand All @@ -108,6 +118,8 @@ func TestConfigWithInvalidPaths(t *testing.T) {
}

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

tests := []struct {
desc string
cfg Config
Expand Down Expand Up @@ -135,7 +147,10 @@ func TestConfigWithMissingAttributes(t *testing.T) {
}

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

cfg := tt.cfg
_, err := cfg.Build()
assert.EqualError(t, err, tt.expectErr)
Expand All @@ -159,6 +174,8 @@ func makeSamplerCountingHook() (h func(zapcore.Entry, zapcore.SamplingDecision),
}

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

shook, dcount, scount := makeSamplerCountingHook()
cfg := Config{
Level: NewAtomicLevelAt(InfoLevel),
Expand Down
11 changes: 11 additions & 0 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ import (
)

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

testEncodersRegistered(t, "console", "json")
}

//nolint:paralleltest // modifies global registry
func TestRegisterEncoder(t *testing.T) {
testEncoders(func() {
assert.NoError(t, RegisterEncoder("foo", newNilEncoder), "expected to be able to register the encoder foo")
testEncodersRegistered(t, "foo")
})
}

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

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

assert.Equal(t, errNoEncoderNameSpecified, RegisterEncoder("", newNilEncoder), "expected an error when registering an encoder with no name")
}

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

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

_, err := newEncoder("foo", zapcore.EncoderConfig{})
assert.Error(t, err, "expected an error when trying to create an encoder of an unregistered name")
}

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

_, err := newEncoder("", zapcore.EncoderConfig{})
assert.Equal(t, errNoEncoderNameSpecified, err, "expected an error when creating an encoder with no name")
}
Expand Down
34 changes: 25 additions & 9 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

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

fail := errors.New("fail")

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

for _, tt := range tests {
if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
}
assertCanBeReused(t, tt.field)
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
}
assertCanBeReused(t, tt.field)
})
}
}

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

tests := []struct {
desc string
field Field
Expand All @@ -70,15 +79,22 @@ func TestErrorArrayConstructor(t *testing.T) {
}

for _, tt := range tests {
enc := zapcore.NewMapObjectEncoder()
tt.field.Key = "k"
tt.field.AddTo(enc)
assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
tt := tt
t.Run(tt.desc, func(t *testing.T) {
t.Parallel()

enc := zapcore.NewMapObjectEncoder()
tt.field.Key = "k"
tt.field.AddTo(enc)
assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
})
}
}

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

errs := []error{fmt.Errorf("egad")}

enc := zapcore.NewMapObjectEncoder()
Expand Down
15 changes: 11 additions & 4 deletions exp/zapfield/zapfield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type (
)

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

var (
key = MyKey("test key")
value = MyValue("test value")
Expand All @@ -55,10 +57,15 @@ func TestFieldConstructors(t *testing.T) {
}

for _, tt := range tests {
if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
}
assertCanBeReused(t, tt.field)
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

if !assert.Equal(t, tt.expect, tt.field, "Unexpected output from convenience field constructor %s.", tt.name) {
t.Logf("type expected: %T\nGot: %T", tt.expect.Interface, tt.field.Interface)
}
assertCanBeReused(t, tt.field)
})
}
}

Expand Down

0 comments on commit 7b6c114

Please sign in to comment.