tls/tests/connection: don't spin waiting for shutdown to complete

Rather than spinning forever waiting for variables to be unreffed by
other threads, sleep for increasingly-long intervals until about 10
seconds pass, and then abort if the variable is still set.

Addresses the current symptoms of
https://bugzilla.gnome.org/show_bug.cgi?id=719727, but not the
underlying leak that appears to be happening in some cases.