MCPcopy
hub / github.com/sirupsen/logrus / TestLoggingWithHooksRace

Function TestLoggingWithHooksRace

hooks/test/test_test.go:42–73  ·  hooks/test/test_test.go::TestLoggingWithHooksRace
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestLoggingWithHooksRace(t *testing.T) {
43
44 r := rand.New(rand.NewSource(time.Now().UnixNano()))
45 unlocker := r.Intn(100)
46
47 assert := assert.New(t)
48 logger, hook := NewNullLogger()
49
50 var wgOne, wgAll sync.WaitGroup
51 wgOne.Add(1)
52 wgAll.Add(100)
53
54 for i := 0; i < 100; i++ {
55 go func(i int) {
56 logger.Info("info")
57 wgAll.Done()
58 if i == unlocker {
59 wgOne.Done()
60 }
61 }(i)
62 }
63
64 wgOne.Wait()
65
66 assert.Equal(logrus.InfoLevel, hook.LastEntry().Level)
67 assert.Equal("info", hook.LastEntry().Message)
68
69 wgAll.Wait()
70
71 entries := hook.AllEntries()
72 assert.Equal(100, len(entries))
73}
74
75func TestFatalWithAlternateExit(t *testing.T) {
76 assert := assert.New(t)

Callers

nothing calls this directly

Calls 5

NewNullLoggerFunction · 0.85
AddMethod · 0.80
LastEntryMethod · 0.80
AllEntriesMethod · 0.80
InfoMethod · 0.65

Tested by

no test coverage detected