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

Function updateFn

kv/memberlist/memberlist_client_test.go:181–206  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

179const key = "test"
180
181func updateFn(name string) func(*data) (*data, bool, error) {
182 return func(in *data) (out *data, retry bool, err error) {
183 // Modify value that was passed as a parameter.
184 // Client takes care of concurrent modifications.
185 r := in
186 if r == nil {
187 r = &data{Members: map[string]member{}}
188 }
189
190 m, ok := r.Members[name]
191 if !ok {
192 r.Members[name] = member{
193 Timestamp: time.Now().Unix(),
194 Tokens: generateTokens(128),
195 State: JOINING,
196 }
197 } else {
198 // We need to update timestamp, otherwise CAS will fail
199 m.Timestamp = time.Now().Unix()
200 m.State = ACTIVE
201 r.Members[name] = m
202 }
203
204 return r, true, nil
205 }
206}
207
208func get(t *testing.T, kv *Client, key string) interface{} {
209 val, err := kv.Get(context.Background(), key)

Callers 9

casWithErrFunction · 0.85
TestBasicGetAndCasFunction · 0.85
TestMultipleCASFunction · 0.85
TestDeleteFunction · 0.85
runClientFunction · 0.85
TestFastJoinFunction · 0.85

Calls 1

generateTokensFunction · 0.85

Tested by

no test coverage detected