Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated NewDeltaFIFO with NewDeltaFIFOWithOptions #100355

Merged
merged 1 commit into from Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion staging/src/k8s.io/client-go/tools/cache/controller_test.go
Expand Up @@ -44,7 +44,10 @@ func Example() {
// This will hold incoming changes. Note how we pass downstream in as a
// KeyLister, that way resync operations will result in the correct set
// of update/delete deltas.
fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, downstream)
fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: MetaNamespaceKeyFunc,
KnownObjects: downstream,
})

// Let's do threadsafe output to get predictable test results.
deletionCounter := make(chan string, 1000)
Expand Down
94 changes: 47 additions & 47 deletions staging/src/k8s.io/client-go/tools/cache/delta_fifo_test.go
Expand Up @@ -56,7 +56,7 @@ func (kl literalListerGetter) GetByKey(key string) (interface{}, bool, error) {
}

func TestDeltaFIFO_basic(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
const amount = 500
go func() {
for i := 0; i < amount; i++ {
Expand Down Expand Up @@ -100,9 +100,12 @@ func TestDeltaFIFO_replaceWithDeleteDeltaIn(t *testing.T) {
oldObj := mkFifoObj("foo", 1)
newObj := mkFifoObj("foo", 2)

f := NewDeltaFIFO(testFifoObjectKeyFunc, literalListerGetter(func() []testFifoObject {
return []testFifoObject{oldObj}
}))
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{oldObj}
}),
})

f.Delete(oldObj)
f.Replace([]interface{}{newObj}, "")
Expand All @@ -118,7 +121,7 @@ func TestDeltaFIFO_replaceWithDeleteDeltaIn(t *testing.T) {
}

func TestDeltaFIFO_requeueOnPop(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})

f.Add(mkFifoObj("foo", 10))
_, err := f.Pop(func(obj interface{}) error {
Expand Down Expand Up @@ -162,7 +165,7 @@ func TestDeltaFIFO_requeueOnPop(t *testing.T) {
}

func TestDeltaFIFO_addUpdate(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
f.Add(mkFifoObj("foo", 10))
f.Update(mkFifoObj("foo", 12))
f.Delete(mkFifoObj("foo", 15))
Expand Down Expand Up @@ -200,7 +203,7 @@ func TestDeltaFIFO_addUpdate(t *testing.T) {
}

func TestDeltaFIFO_enqueueingNoLister(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
f.Add(mkFifoObj("foo", 10))
f.Update(mkFifoObj("bar", 15))
f.Add(mkFifoObj("qux", 17))
Expand All @@ -221,12 +224,12 @@ func TestDeltaFIFO_enqueueingNoLister(t *testing.T) {
}

func TestDeltaFIFO_enqueueingWithLister(t *testing.T) {
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
}),
)
})
f.Add(mkFifoObj("foo", 10))
f.Update(mkFifoObj("bar", 15))

Expand All @@ -245,7 +248,7 @@ func TestDeltaFIFO_enqueueingWithLister(t *testing.T) {
}

func TestDeltaFIFO_addReplace(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
f.Add(mkFifoObj("foo", 10))
f.Replace([]interface{}{mkFifoObj("foo", 15)}, "0")
got := make(chan testFifoObject, 2)
Expand All @@ -271,12 +274,12 @@ func TestDeltaFIFO_addReplace(t *testing.T) {
}

func TestDeltaFIFO_ResyncNonExisting(t *testing.T) {
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5)}
}),
)
})
f.Delete(mkFifoObj("foo", 10))
f.Resync()

Expand All @@ -290,12 +293,12 @@ func TestDeltaFIFO_ResyncNonExisting(t *testing.T) {
}

func TestDeltaFIFO_Resync(t *testing.T) {
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5)}
}),
)
})
f.Resync()

deltas := f.items["foo"]
Expand All @@ -308,12 +311,12 @@ func TestDeltaFIFO_Resync(t *testing.T) {
}

func TestDeltaFIFO_DeleteExistingNonPropagated(t *testing.T) {
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{}
}),
)
})
f.Add(mkFifoObj("foo", 5))
f.Delete(mkFifoObj("foo", 6))

Expand All @@ -331,12 +334,12 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) {
// promise about how their deletes are ordered.

// Try it with a pre-existing Delete
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
}),
)
})
f.Delete(mkFifoObj("baz", 10))
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")

Expand All @@ -356,12 +359,12 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) {
}

// Now try starting with an Add instead of a Delete
f = NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f = NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
}),
)
})
f.Add(mkFifoObj("baz", 10))
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")

Expand All @@ -382,10 +385,7 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) {
}

// Now try starting without an explicit KeyListerGetter
f = NewDeltaFIFO(
testFifoObjectKeyFunc,
nil,
)
f = NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
f.Add(mkFifoObj("baz", 10))
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")

Expand Down Expand Up @@ -458,12 +458,12 @@ func TestDeltaFIFO_ReplaceDeltaType(t *testing.T) {
}

func TestDeltaFIFO_UpdateResyncRace(t *testing.T) {
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5)}
}),
)
})
f.Update(mkFifoObj("foo", 6))
f.Resync()

Expand All @@ -480,12 +480,12 @@ func TestDeltaFIFO_UpdateResyncRace(t *testing.T) {
}

func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) {
f := NewDeltaFIFO(
testFifoObjectKeyFunc,
literalListerGetter(func() []testFifoObject {
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{
KeyFunction: testFifoObjectKeyFunc,
KnownObjects: literalListerGetter(func() []testFifoObject {
return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)}
}),
)
})
f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0")

expectedList := []Deltas{
Expand All @@ -511,7 +511,7 @@ func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) {
}

func TestDeltaFIFO_detectLineJumpers(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})

f.Add(mkFifoObj("foo", 10))
f.Add(mkFifoObj("bar", 1))
Expand Down Expand Up @@ -539,7 +539,7 @@ func TestDeltaFIFO_detectLineJumpers(t *testing.T) {
}

func TestDeltaFIFO_addIfNotPresent(t *testing.T) {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})

f.Add(mkFifoObj("b", 3))
b3 := Pop(f)
Expand Down Expand Up @@ -645,7 +645,7 @@ func TestDeltaFIFO_HasSynced(t *testing.T) {
}

for i, test := range tests {
f := NewDeltaFIFO(testFifoObjectKeyFunc, nil)
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})

for _, action := range test.actions {
action(f)
Expand Down