[resultdb] Fix flaky timeout in history.Query.collect()
[resultdb] Fix flaky timeout in history.Query.collect()

This is caused because `wi.resultsC` is not guaranteed to be closed
until after a worker has picked up `wi`, but this may not happen if all
workers have already terminated (e.g. due to the context expiring).

So, if the collector has already blocked on the results channel of a
workItem that is _not_ going to be picked up, it will wait forever.

This race is fixed by replacing the range over `wi.resultsC` with a
loop over a select that checks the context and receives on the channel
simultaneously.

R=chanli,nodir,ddoman

Change-Id: I82b150373406ce3ff1c83970dcb0f9b2028cdb6a
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/2589900
Reviewed-by: Nodir Turakulov <ef4933a197ef7b4b3f55f1bec4942aead3637a2a@chromium.org>
Reviewed-by: Chan Li <332b6c56634d0f63001046c664a2370006a02420@chromium.org>
Commit-Queue: Roberto Carrillo <b31161e510fbb37f8f70fdcde11530d2bae88470@chromium.org>

luci/luci-go,luci/luci-go,luci/luci-go,luci/luci-go,luci/luci-go,luci/luci-go