Don't pop the command queue when PubSub messages are received

I debugged this issue just before discovering @cxreg had independently logged this issue in #342 and submitted pull request #356 to fix it. 

@cxreg's fix looks good, however I decided to submit this separate pull request for two reasons:

1. @cxreg's fix seems to break a couple of tests (the extra checks to ensure the `reply` array contains at least one non-null item seem to be necessary to make them pass).

2. I wrote a couple of extra unit tests to reproduce the issue and prove the fix addresses it. This adds a little more value.

---
Ready to merge checklist
- [x] test(s)
- [x] does the test fail without for PR but succeed once applied?
- [x] docs, if applicable
- [ ] merges cleanly
- [x] coding style (4-space indents, looks similar to other code)