I am writing some e2e test in GO where a test ldap server is run via a Go routine. Then I run my tests via t.Run()
. Sometimes tests fail because the server has not started yet. I have tried adding upto 10 secs of sleep before starting tests. But things are still flaky (especially on travis ci).
I could probably use ldap client to detect if the connect operation succeeds or not before calling t.Run()
. But I am wondering if there is a more generic solution where a Go process can check if a port if already bound by some process. I am looking for something like lsof
or netstat
in Go.
I have searched online and found some solution where net.Listen
is used to bind for that port and see if that succeeds or not. Obviously I don't want to do that since that will be fighting with my own code. Any ideas are welcome!
Thanks.