assumevalid.py, example_test.py, p2p-acceptblocks.py and
abc-p2p-compactblocks add p2p_connections after the
NetworkThread has been started. This isn't permitted.
Fix test to restart the network thread when adding new connections.
Add assertions to ensure new tests won't fail into this issue.
p2p-leaktest.py had a potential race condition if the NetworkThread
hadn't terminated by the time we tried to restart it.
Partial backport of core PR11849
commits 5c8ff26 and 34e08b3
Depends on D2383