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

Function TestSyncSubscriptionPendingDrain

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

Source from the content-addressed store, hash-verified

1254}
1255
1256func TestSyncSubscriptionPendingDrain(t *testing.T) {
1257 s := RunDefaultServer()
1258 defer s.Shutdown()
1259
1260 nc := NewDefaultConnection(t)
1261 defer nc.Close()
1262
1263 // Send some messages to ourselves.
1264 total := 100
1265 msg := []byte("0123456789")
1266
1267 sub, _ := nc.SubscribeSync("foo")
1268 defer sub.Unsubscribe()
1269
1270 for range total {
1271 nc.Publish("foo", msg)
1272 }
1273 nc.Flush()
1274
1275 // Wait for all delivered.
1276 for d, _ := sub.Delivered(); d != int64(total); d, _ = sub.Delivered() {
1277 sub.NextMsg(10 * time.Millisecond)
1278 }
1279
1280 m, b, _ := sub.Pending()
1281 if m != 0 {
1282 t.Fatalf("Expected msgs of 0, got %d", m)
1283 }
1284 if b != 0 {
1285 t.Fatalf("Expected bytes of 0, got %d", b)
1286 }
1287
1288 sub.Unsubscribe()
1289 if _, err := sub.Delivered(); err == nil {
1290 t.Fatal("Calling Delivered() on closed subscription should fail")
1291 }
1292}
1293
1294func TestSyncSubscriptionPending(t *testing.T) {
1295 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 11

UnsubscribeMethod · 0.80
DeliveredMethod · 0.80
NextMsgMethod · 0.80
PendingMethod · 0.80
FatalfMethod · 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