testSelectionTool: open connection in worker thread

In ZODB 5, with commit b6ac40f1 (Uses an unwrapped transaction manager,
2018-10-14) the transaction is bound to the thread opening the
connection.
The previous pattern of opening transaction in the main thread and
passing the already-open connection to the working thread caused the
working thread connection to be managed by the main thread connection
and in ZODB 5 cause the test to block.

Fix this by passing a connection factory method and opening
connection in working thread.
Also simplify closing of connection by using a closing context manager.
9 jobs for fix/periodicity_impossible_combinations in 0 seconds
Status Job ID Name Coverage
  External
failed ERP5.UnitTest-Master

01:02:22

passed SlapOS.Eggs.UnitTest-Master.Python2

00:10:00

passed SlapOS.Eggs.UnitTest-Master.Python3

00:21:53

failed ERP5.UnitTest-Master

01:10:35

failed ERP5.UnitTest-Master

03:58:29

passed SlapOS.Eggs.UnitTest-Master.Python2

00:10:29

passed SlapOS.Eggs.UnitTest-Master.Python2

00:10:09

passed SlapOS.Eggs.UnitTest-Master.Python3

00:14:39

passed SlapOS.Eggs.UnitTest-Master.Python3

00:11:40