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

Function TestCAS

kv/kv_test.go:52–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50)
51
52func TestCAS(t *testing.T) {
53 withFixtures(t, func(t *testing.T, client Client) {
54 // Blindly set key to "0".
55 err := client.CAS(ctx, key, func(interface{}) (interface{}, bool, error) {
56 return "0", true, nil
57 })
58 require.NoError(t, err)
59
60 // Swap key to i+1 iff its i.
61 for i := 0; i < 10; i++ {
62 err = client.CAS(ctx, key, func(in interface{}) (interface{}, bool, error) {
63 require.EqualValues(t, strconv.Itoa(i), in)
64 return strconv.Itoa(i + 1), true, nil
65 })
66 require.NoError(t, err)
67 }
68
69 // Make sure the CASes left the right value - "10".
70 value, err := client.Get(ctx, key)
71 require.NoError(t, err)
72 require.EqualValues(t, "10", value)
73 })
74}
75
76// TestNilCAS ensures we can return nil from the CAS callback when we don't
77// want to modify the value.

Callers

nothing calls this directly

Calls 3

withFixturesFunction · 0.70
CASMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected