baudehlo/Haraka — pull request #778 by smfreegard (2014-12-11 13:55:28+00:00)
Title: Fix #777, improve tests, add cb_each

#746 introduced a bug and a behavioural change in dns_list_base which broke the first() function which is the default method for the dnsbl and dnswl plugins which caused them not to return next() at all.

This PR fixes issue #777 by:

- Introducing additional tests on the first() function which exposed the failure.
- Changing the pending variable from an integer to a boolean (which was the breaking change in #746) and proving the test that was failing now passes.

However; there's been a subtle change in behaviour from pre #746 to post in that the multi() callback previously was called once per zone whereas now it is called once per zone + 1 due to the switch to async.series. This was because the previous code used 'pending' as a counter of the number of results remaining which then called next() when pending === 0 meaning we returned on the last result to come in. This won't cause an issue in any of the stock plugins, but if anyone has a custom plugin that inherited dns_list_base, then this might be an unwelcome surprise - I'm therefore documenting this change here and we can discuss if this should be reverted.

I have additionally:

- Modified the existing tests to better check output variables and testing the behaviour above (e.g. zones + 1 callbacks).
- Added a new cb_each() callback to the first() method which is called for every result returned.
- Made the dnsbl connect_first() function use cb_each to set connection results for each result returned so that it matches connect_multi().