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

Function TestIsValidSubscriber

test/sub_test.go:423–450  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

421}
422
423func TestIsValidSubscriber(t *testing.T) {
424 s := RunDefaultServer()
425 defer s.Shutdown()
426
427 nc := NewDefaultConnection(t)
428 defer nc.Close()
429
430 sub, err := nc.SubscribeSync("foo")
431 if err != nil {
432 t.Fatalf("Error on subscribe: %v", err)
433 }
434 if !sub.IsValid() {
435 t.Fatalf("Subscription should be valid")
436 }
437 for range 10 {
438 nc.Publish("foo", []byte("Hello"))
439 }
440 nc.Flush()
441 _, err = sub.NextMsg(200 * time.Millisecond)
442 if err != nil {
443 t.Fatalf("NextMsg returned an error")
444 }
445 sub.Unsubscribe()
446 _, err = sub.NextMsg(200 * time.Millisecond)
447 if err == nil {
448 t.Fatalf("NextMsg should have returned an error")
449 }
450}
451
452func TestSlowSubscriber(t *testing.T) {
453 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 10

FatalfMethod · 0.80
IsValidMethod · 0.80
NextMsgMethod · 0.80
UnsubscribeMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
SubscribeSyncMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected