MCPcopy
hub / github.com/uber-go/zap / TestLoggerConcurrent

Function TestLoggerConcurrent

logger_test.go:798–826  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

796}
797
798func TestLoggerConcurrent(t *testing.T) {
799 withLogger(t, DebugLevel, nil, func(logger *Logger, logs *observer.ObservedLogs) {
800 child := logger.With(String("foo", "bar"))
801
802 wg := &sync.WaitGroup{}
803 runConcurrently(5, 10, wg, func() {
804 logger.Info("", String("foo", "bar"))
805 })
806 runConcurrently(5, 10, wg, func() {
807 child.Info("")
808 })
809
810 wg.Wait()
811
812 // Make sure the output doesn't contain interspersed entries.
813 assert.Equal(t, 100, logs.Len(), "Unexpected number of logs written out.")
814 for _, obs := range logs.AllUntimed() {
815 assert.Equal(
816 t,
817 observer.LoggedEntry{
818 Entry: zapcore.Entry{Level: InfoLevel},
819 Context: []Field{String("foo", "bar")},
820 },
821 obs,
822 "Unexpected log output.",
823 )
824 }
825 })
826}
827
828func TestLoggerFatalOnNoop(t *testing.T) {
829 exitStub := exit.Stub()

Callers

nothing calls this directly

Calls 7

StringFunction · 0.85
runConcurrentlyFunction · 0.85
AllUntimedMethod · 0.80
withLoggerFunction · 0.70
WithMethod · 0.65
InfoMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected