The behavior was not previous covered and broke in N
due to commit c80af6d8. There is an associated fix
in frameworks/base.
Some refactoring of existing tests to reduce
duplication and tidy up sockets after tests.
Test: Ran the new CTS test (before and after related fix)
Bug: 31205169
(cherry picked from commit 52376fc1c8)
Change-Id: I9ee96a91abbdaaba64c2f6daf49c92d1b23352e2