mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Fix line-jumping bug in FIFO implementation
Keep the FIFO's internal set in sync with the queue during Add/Update operations to prevent a queue line-jumping scenario (described in a new unit test).
This commit is contained in:
28
pkg/client/cache/fifo_test.go
vendored
28
pkg/client/cache/fifo_test.go
vendored
@@ -107,3 +107,31 @@ func TestFIFO_addReplace(t *testing.T) {
|
||||
t.Errorf("item did not get removed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFIFO_detectLineJumpers(t *testing.T) {
|
||||
f := NewFIFO()
|
||||
|
||||
f.Add("foo", 10)
|
||||
f.Add("bar", 1)
|
||||
f.Add("foo", 11)
|
||||
f.Add("foo", 13)
|
||||
f.Add("zab", 30)
|
||||
|
||||
if e, a := 13, f.Pop().(int); a != e {
|
||||
t.Fatalf("expected %d, got %d", e, a)
|
||||
}
|
||||
|
||||
f.Add("foo", 14) // ensure foo doesn't jump back in line
|
||||
|
||||
if e, a := 1, f.Pop().(int); a != e {
|
||||
t.Fatalf("expected %d, got %d", e, a)
|
||||
}
|
||||
|
||||
if e, a := 30, f.Pop().(int); a != e {
|
||||
t.Fatalf("expected %d, got %d", e, a)
|
||||
}
|
||||
|
||||
if e, a := 14, f.Pop().(int); a != e {
|
||||
t.Fatalf("expected %d, got %d", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user