tests: pubsub: fix racy tests.

Use `once` instead of `on`, and also `close` the connection for good housekeeping.
Only did switch -> if for consistency with our other test stubs.