test: Fix tls tests which fail sporadically

The count of ECONNRESETs is dependent on timing, and thus unreliable,
especially on Linux machines.
tls: Write pending data on socket drain

Fixes #4800