test: fix flaky http-server-keep-alive-timeout
Make sure the connection is not closed until the 3 requests and the
timeout
event are received.
Some code refactoring to avoid duplicated code.
Fixes: https://github.com/nodejs/node/issues/20013
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines