-
Notifications
You must be signed in to change notification settings - Fork 4
Description
A fully Asynchronous buffer (one which raises events on timer not just on capacity) will lead to some problems with interrupted actions.
There may be more, but so far it looks like changing filter mode/ sort mode will have the biggest effect. Changing one of these modes while the buffer is filling up will lead to the buffer containing some unsorted/unfiltered data - the content wrapper expects fully sorted+filtered data.
Only the first batch out of the buffer after re-sort/filter can be affected by this problem though - as any new items that trigger buffer events will necessarily match the Sort/Filter criteria, it's only the ones already in the buffer that we need to worry about.
- Change filter mode
- Buffer will contain some items that match the current filter, and some that match the old
- If the re-filter reaches buffer capacity, the mixed items will be added, triggering an incorrect event, but then the content wrapper will filter them out
- If the re-filter doesn't fill the buffer, the content will re-filter first then the buffer items will be added when the buffer timeouts - this will leave incorrect items in the content wrapper v bad
- Change sort mode
- Buffer will contain a mix of sorted and unsorted stuff
- If buffer overflows first, items will be added (duplicates removed, i.e. only unsorted stuff remains). These don't match the actual sort order, so if
SortOnAddition
is set then the wrong item will be tracked, and the incorrect event will be raised. Then content wrapper will sort correctly - If buffer doesn't overflow, the content will sort first and then the buffer items will be added on timeout. The wrong event will be raised and the content will remain unsorted
A combination of the two is feasible and messy.
Solution:
Perhaps the buffer could be flushed to avoid these problems. But better would be to sort and filter buffer items after leaving the buffer rather than when entering, as this is a synchronous uninterruptible process.
Unit tests for these interrupted actions should be included