As we need to find unused ports for testing of our bots, we also need to know them in the test environment,
which means that we can't just let bot listen on port 0,
because we don't have a proper backchannel to understand which ports are used
This function spawns net.servers on port 0, gets, which ports they used, and frees it.
Unlike using port 0, this approach doesn't really guarantee that port will be free until app starts listening,
but should be pretty stable
A caveat here: if you free a port and try getting a new one in a row, you might get the same one,
thus, spawning multiple servers together, and closing them together as well
As we need to find unused ports for testing of our bots, we also need to know them in the test environment, which means that we can't just let bot listen on port 0, because we don't have a proper backchannel to understand which ports are used
This function spawns
net.server
s on port 0, gets, which ports they used, and frees it. Unlike using port 0, this approach doesn't really guarantee that port will be free until app starts listening, but should be pretty stableA caveat here: if you free a port and try getting a new one in a row, you might get the same one, thus, spawning multiple servers together, and closing them together as well