Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/cache/v3/linear.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ func (cache *LinearCache) CreateDeltaWatch(request *DeltaRequest, sub Subscripti
return cache.trackWatch(watch), nil
}

func (cache *LinearCache) GetVersion() uint64 {
return cache.version
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be returned without concurrency protection. version is only touched under lock today.
Also the version integer is an internal detail. The version from a public API point-of-view is a string with the provided version prefix, not this integer

}

func (cache *LinearCache) nextWatchID() uint64 {
cache.currentWatchID++
if cache.currentWatchID == 0 {
Expand Down
20 changes: 20 additions & 0 deletions pkg/cache/v3/linear_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,26 @@ func TestLinearGetResources(t *testing.T) {
assert.Truef(t, reflect.DeepEqual(expectedResources, resources), "resources are not equal. got: %v want: %v", resources, expectedResources)
}

func TestLinearGetVersion(t *testing.T) {
c := NewLinearCache(testType)
assert.Equal(t, uint64(0), c.GetVersion())

require.NoError(t, c.UpdateResource("a", testResource("a")))
assert.Equal(t, uint64(1), c.GetVersion())

require.NoError(t, c.UpdateResource("b", testResource("b")))
assert.Equal(t, uint64(2), c.GetVersion())

require.NoError(t, c.DeleteResource("a"))
assert.Equal(t, uint64(3), c.GetVersion())

require.NoError(t, c.UpdateResources(map[string]types.Resource{"c": testResource("c")}, []string{"b"}))
assert.Equal(t, uint64(4), c.GetVersion())

c.SetResources(map[string]types.Resource{"d": testResource("d")})
assert.Equal(t, uint64(5), c.GetVersion())
}

func TestLinearVersionPrefix(t *testing.T) {
c := NewLinearCache(testType, WithVersionPrefix("instance1-"))

Expand Down