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

Function TestFastJoin

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

Source from the content-addressed store, hash-verified

1879}
1880
1881func TestFastJoin(t *testing.T) {
1882 var cfg KVConfig
1883 flagext.DefaultValues(&cfg)
1884 cfg.TCPTransport = TCPTransportConfig{
1885 BindAddrs: getLocalhostAddrs(),
1886 BindPort: 0, // randomize
1887 }
1888
1889 cfg.Codecs = []codec.Codec{
1890 dataCodec{},
1891 }
1892
1893 mkv1 := NewKV(cfg, log.NewNopLogger(), &staticDNSProviderMock{}, prometheus.NewPedanticRegistry())
1894 require.NoError(t, services.StartAndAwaitRunning(context.Background(), mkv1))
1895 defer services.StopAndAwaitTerminated(context.Background(), mkv1) //nolint:errcheck
1896
1897 kv1, err := NewClient(mkv1, dataCodec{})
1898 require.NoError(t, err)
1899
1900 const memberKey = "entry"
1901
1902 // Calling updateFn once creates single entry, in JOINING state.
1903 err = cas(kv1, key, updateFn(memberKey))
1904 require.NoError(t, err)
1905
1906 // We will read values from second KV, which will join the first one
1907 cfg.JoinMembers = []string{net.JoinHostPort("127.0.0.1", strconv.Itoa(mkv1.GetListeningPort()))}
1908
1909 mkv2 := NewKV(cfg, log.NewNopLogger(), &staticDNSProviderMock{}, prometheus.NewPedanticRegistry())
1910 go func() {
1911 // Wait a bit, and then start mkv2.
1912 time.Sleep(500 * time.Millisecond)
1913 require.NoError(t, services.StartAndAwaitRunning(context.Background(), mkv2))
1914 }()
1915
1916 defer services.StopAndAwaitTerminated(context.Background(), mkv2) //nolint:errcheck
1917
1918 // While waiting for mkv2 to start, we can already create a client for it.
1919 // Any client operations will block until mkv2 transitioned to Running state.
1920 kv2, err := NewClient(mkv2, dataCodec{})
1921 require.NoError(t, err)
1922
1923 val, err := kv2.Get(context.Background(), key)
1924 require.NoError(t, err)
1925 require.NotNil(t, val)
1926 require.NotZero(t, val.(*data).Members[memberKey].Timestamp)
1927 require.Equal(t, JOINING, val.(*data).Members[memberKey].State)
1928}
1929
1930func TestDelegateMethodsDontCrashBeforeKVStarts(t *testing.T) {
1931 codec := dataCodec{}

Callers

nothing calls this directly

Calls 12

GetListeningPortMethod · 0.95
GetMethod · 0.95
DefaultValuesFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
getLocalhostAddrsFunction · 0.85
NewKVFunction · 0.85
casFunction · 0.85
updateFnFunction · 0.85
NewClientFunction · 0.70
SleepMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected