package mqsvr import ( "strconv" "testing" "time" ) const ( addr = "127.0.0.1:4222" ) func TestNats_Close(t *testing.T) { n, err := NewNats([]string{"127.0.0.1:4222"}, "test", "test", "n1") if err != nil { t.Fatal(err) } n.Close() } func TestNats_Pub(t *testing.T) { c1, err := NewNats([]string{"127.0.0.1:4222"}, "test", "test", "n1") if err != nil { t.Fatal(err) } c2, err := NewNats([]string{"127.0.0.1:4222"}, "test", "test", "n1") if err != nil { t.Fatal(err) } defer func() { c1.Close() c2.Close() }() // publisher go func() { for i := 0; i < 10; i++ { _ = c1.Pub("test.ok", []byte("test "+strconv.FormatInt(int64(i), 10)), time.Second) time.Sleep(time.Second) } }() //// IMPORTANT: comment this line and run test again. there will be no message lost. time.Sleep(3 * time.Second) go func() { _, err := c2.Sub("test.ok", func(subj string, data []byte) { t.Log("received from " + subj + ", data:" + string(data)) }) if err != nil { t.Fatal(err) } }() time.Sleep(11 * time.Second) } func TestNats_Sub(t *testing.T) { } func TestNats_QSub(t *testing.T) { }