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

Function TestCASNoChangeShortTimeout

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

Source from the content-addressed store, hash-verified

528}
529
530func TestCASNoChangeShortTimeout(t *testing.T) {
531 withFixtures(t, func(t *testing.T, kv *Client) {
532 err := cas(kv, key, func(in *data) (*data, bool, error) {
533 if in == nil {
534 in = &data{Members: map[string]member{}}
535 }
536
537 in.Members["hello"] = member{
538 Timestamp: time.Now().Unix(),
539 Tokens: generateTokens(128),
540 State: JOINING,
541 }
542
543 return in, true, nil
544 })
545 require.NoError(t, err)
546
547 ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
548 defer cancel()
549
550 calls := 0
551 err = casWithErr(ctx, kv, key, func(d *data) (*data, bool, error) {
552 calls++
553 return d, true, nil
554 })
555 require.EqualError(t, err, "failed to CAS-update key test: context deadline exceeded")
556 require.Equal(t, 1, calls) // hard-coded in CAS function.
557 })
558}
559
560func TestCASFailedBecauseOfVersionChanges(t *testing.T) {
561 withFixtures(t, func(t *testing.T, kv *Client) {

Callers

nothing calls this directly

Calls 5

casFunction · 0.85
generateTokensFunction · 0.85
casWithErrFunction · 0.85
withFixturesFunction · 0.70
EqualMethod · 0.45

Tested by

no test coverage detected