| 213 | } |
| 214 | |
| 215 | func TestDeltaFIFO_addReplace(t *testing.T) { |
| 216 | f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) |
| 217 | f.Add(mkFifoObj("foo", 10)) |
| 218 | f.Replace([]interface{}{mkFifoObj("foo", 15)}, "0") |
| 219 | got := make(chan testFifoObject, 2) |
| 220 | go func() { |
| 221 | for { |
| 222 | got <- testPop(f) |
| 223 | } |
| 224 | }() |
| 225 | |
| 226 | first := <-got |
| 227 | if e, a := 15, first.val; e != a { |
| 228 | t.Errorf("Didn't get updated value (%v), got %v", e, a) |
| 229 | } |
| 230 | select { |
| 231 | case unexpected := <-got: |
| 232 | t.Errorf("Got second value %v", unexpected.val) |
| 233 | case <-time.After(50 * time.Millisecond): |
| 234 | } |
| 235 | _, exists, _ := f.Get(mkFifoObj("foo", "")) |
| 236 | if exists { |
| 237 | t.Errorf("item did not get removed") |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | func TestDeltaFIFO_ResyncNonExisting(t *testing.T) { |
| 242 | f := NewDeltaFIFO( |