MCPcopy
hub / github.com/grafana/dskit / TestDelete

Function TestDelete

kv/memberlist/memberlist_client_test.go:700–749  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

698}
699
700func TestDelete(t *testing.T) {
701 t.Parallel()
702
703 c := dataCodec{}
704
705 reg := prometheus.NewRegistry()
706
707 var cfg KVConfig
708 flagext.DefaultValues(&cfg)
709 cfg.TCPTransport = TCPTransportConfig{
710 BindAddrs: getLocalhostAddrs(),
711 BindPort: 0, // randomize ports
712 }
713 cfg.GossipNodes = 1
714 cfg.GossipInterval = 100 * time.Millisecond
715 cfg.ObsoleteEntriesTimeout = 500 * time.Millisecond
716 cfg.ClusterLabelVerificationDisabled = true
717 cfg.Codecs = []codec.Codec{c}
718
719 mkv := NewKV(cfg, log.NewNopLogger(), &staticDNSProviderMock{}, reg)
720 require.NoError(t, services.StartAndAwaitRunning(context.Background(), mkv))
721 defer services.StopAndAwaitTerminated(context.Background(), mkv) //nolint:errcheck
722
723 kv, err := NewClient(mkv, c)
724 require.NoError(t, err)
725
726 const key = "test"
727
728 val := get(t, kv, key)
729 if val != nil {
730 t.Error("Expected nil, got:", val)
731 }
732
733 err = cas(kv, key, updateFn("test"))
734 require.NoError(t, err)
735
736 err = kv.Delete(context.Background(), key)
737 if err != nil {
738 t.Fatalf("Failed to delete key %s: %v", key, err)
739 }
740
741 checkMemberlistEntry(t, kv, key, 2*time.Second)
742
743 // Validate that there are no encoding errors during the Delete flow.
744 assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
745 # HELP memberlist_client_messages_to_broadcast_dropped_total Number of broadcast messages intended to be sent but were dropped due to encoding errors or for being too big
746 # TYPE memberlist_client_messages_to_broadcast_dropped_total counter
747 memberlist_client_messages_to_broadcast_dropped_total 0
748 `), "memberlist_client_messages_to_broadcast_dropped_total"))
749}
750
751func TestDeleteMultipleClients(t *testing.T) {
752

Callers

nothing calls this directly

Calls 13

DeleteMethod · 0.95
DefaultValuesFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
getLocalhostAddrsFunction · 0.85
NewKVFunction · 0.85
getFunction · 0.85
casFunction · 0.85
updateFnFunction · 0.85
checkMemberlistEntryFunction · 0.85
FatalfMethod · 0.80
NewClientFunction · 0.70

Tested by

no test coverage detected