(t *testing.T)
| 528 | } |
| 529 | |
| 530 | func 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 | |
| 560 | func TestCASFailedBecauseOfVersionChanges(t *testing.T) { |
| 561 | withFixtures(t, func(t *testing.T, kv *Client) { |
nothing calls this directly
no test coverage detected