[lib/connection]Add tests for MessageQueue, and fix bug where deque returned empty result if first N-messages were expired, even if the following weren't.