MCPcopy
hub / github.com/nats-io/nats.go / TestStatsRace

Function TestStatsRace

test/nats_test.go:800–834  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

798}
799
800func TestStatsRace(t *testing.T) {
801 o := natsserver.DefaultTestOptions
802 o.Port = -1
803 s := RunServerWithOptions(&o)
804 defer s.Shutdown()
805
806 nc, err := nats.Connect(fmt.Sprintf("nats://%s:%d", o.Host, o.Port))
807 if err != nil {
808 t.Fatalf("Error on connect: %v", err)
809 }
810 defer nc.Close()
811
812 wg := sync.WaitGroup{}
813 wg.Add(1)
814 ch := make(chan bool)
815 go func() {
816 defer wg.Done()
817 for {
818 select {
819 case <-ch:
820 return
821 default:
822 nc.Stats()
823 }
824 }
825 }()
826
827 nc.Subscribe("foo", func(_ *nats.Msg) {})
828 for i := 0; i < 1000; i++ {
829 nc.Publish("foo", []byte("hello"))
830 }
831
832 close(ch)
833 wg.Wait()
834}
835
836func TestRequestLeaksMapEntries(t *testing.T) {
837 o := natsserver.DefaultTestOptions

Callers

nothing calls this directly

Calls 9

ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerWithOptionsFunction · 0.70
AddMethod · 0.65
DoneMethod · 0.65
StatsMethod · 0.65
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected