| 150 | } |
| 151 | |
| 152 | func TestFIFO_addReplace(t *testing.T) { |
| 153 | f := NewFIFO(testFifoObjectKeyFunc) |
| 154 | f.Add(mkFifoObj("foo", 10)) |
| 155 | f.Replace([]interface{}{mkFifoObj("foo", 15)}, "15") |
| 156 | got := make(chan testFifoObject, 2) |
| 157 | go func() { |
| 158 | for { |
| 159 | got <- Pop(f).(testFifoObject) |
| 160 | } |
| 161 | }() |
| 162 | |
| 163 | first := <-got |
| 164 | if e, a := 15, first.val; e != a { |
| 165 | t.Errorf("Didn't get updated value (%v), got %v", e, a) |
| 166 | } |
| 167 | select { |
| 168 | case unexpected := <-got: |
| 169 | t.Errorf("Got second value %v", unexpected.val) |
| 170 | case <-time.After(50 * time.Millisecond): |
| 171 | } |
| 172 | _, exists, _ := f.Get(mkFifoObj("foo", "")) |
| 173 | if exists { |
| 174 | t.Errorf("item did not get removed") |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | func TestFIFO_detectLineJumpers(t *testing.T) { |
| 179 | f := NewFIFO(testFifoObjectKeyFunc) |