Made test more robust.

The check for the connection being closed may fail spuriously because
the notification of CompleteListener happens before the connection is
closed.