tls/tests: try to fix a flaky test

test_close_during_handshake() and test_write_during_handshake()
require that the handshake complete after the test runs, but they were
assuming that iterating the context a single time would cause that to
happen. While that *should* be true, that relies on a lot of
assumptions (and apparently it's not always true anyway). So fix them
to wait for the handshake's callback rather than just trying to guess
when it's done.

https://bugzilla.gnome.org/show_bug.cgi?id=722336