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

Function TestKeyValueWatchContext

jetstream/test/kv_test.go:702–729  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

700}
701
702func TestKeyValueWatchContext(t *testing.T) {
703 s := RunBasicJetStreamServer()
704 defer shutdownJSServerAndRemoveStorage(t, s)
705
706 nc, js := jsClient(t, s)
707 defer nc.Close()
708 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
709 defer cancel()
710
711 kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "WATCHCTX"})
712 expectOk(t, err)
713
714 watcher, err := kv.WatchAll(ctx)
715 expectOk(t, err)
716 defer watcher.Stop()
717
718 // Trigger unsubscribe internally.
719 cancel()
720
721 // Wait for a bit for unsubscribe to be done.
722 time.Sleep(500 * time.Millisecond)
723
724 // Stopping watch that is already stopped via cancellation propagation is an error.
725 err = watcher.Stop()
726 if err == nil || err != nats.ErrBadSubscription {
727 t.Errorf("Expected invalid subscription, got: %v", err)
728 }
729}
730
731func TestKeyValueWatchContextUpdates(t *testing.T) {
732 s := RunBasicJetStreamServer()

Callers

nothing calls this directly

Calls 9

ErrorfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
jsClientFunction · 0.70
expectOkFunction · 0.70
CreateKeyValueMethod · 0.65
WatchAllMethod · 0.65
StopMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected