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

Function TestLoggingRaceWithHooksOnEntry

logrus_test.go:584–633  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

582}
583
584func TestLoggingRaceWithHooksOnEntry(t *testing.T) {
585 logger := New()
586 hook := new(ModifyHook)
587 logger.AddHook(hook)
588 entry := logger.WithField("context", "clue")
589
590 var (
591 wg sync.WaitGroup
592 mtx sync.Mutex
593 start bool
594 )
595
596 cond := sync.NewCond(&mtx)
597
598 wg.Add(100)
599
600 for i := 0; i < 50; i++ {
601 go func() {
602 cond.L.Lock()
603 for !start {
604 cond.Wait()
605 }
606 cond.L.Unlock()
607 for j := 0; j < 100; j++ {
608 entry.Info("info")
609 }
610 wg.Done()
611 }()
612 }
613
614 for i := 0; i < 50; i++ {
615 go func() {
616 cond.L.Lock()
617 for !start {
618 cond.Wait()
619 }
620 cond.L.Unlock()
621 for j := 0; j < 100; j++ {
622 entry.WithField("another field", "with some data").Info("info")
623 }
624 wg.Done()
625 }()
626 }
627
628 cond.L.Lock()
629 start = true
630 cond.L.Unlock()
631 cond.Broadcast()
632 wg.Wait()
633}
634
635func TestReplaceHooks(t *testing.T) {
636 old, cur := &TestHook{}, &TestHook{}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
AddHookMethod · 0.80
AddMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
WithFieldMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected