tests: pubsub: fix racy tests.

Use `once` instead of `on`, and also `close` the connection for good housekeeping.