fix: ooporthelper connection_refused (#974)

Closes https://github.com/ooni/probe/issues/2338

Co-authored-by: decfox <decfox@github.com>
This commit is contained in:
DecFox 2022-10-08 13:56:08 +05:30 committed by GitHub
commit 62e9f8e101
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View file

@ -9,13 +9,19 @@ import (
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
var (
portsMap = make(map[string]bool)
)
func TestMainWorkingAsIntended(t *testing.T) {
t.Skip("// TODO(https://github.com/ooni/probe/issues/2338)")
srvTest = true // toggle to imply that we are running in test mode
for _, port := range TestPorts {
portsMap[port] = false
}
go main()
dialer := netxlite.NewDialerWithoutResolver(model.DiscardLogger)
for _, port := range TestPorts {
<-srvTestChan
for i := 0; i < len(TestPorts); i++ {
port := <-srvTestChan
addr := net.JoinHostPort("127.0.0.1", port)
ctx := context.Background()
conn, err := dialer.DialContext(ctx, "tcp", addr)
@ -26,7 +32,14 @@ func TestMainWorkingAsIntended(t *testing.T) {
t.Fatal("expected non-nil conn")
}
conn.Close()
portsMap[port] = true
}
srvCancel() // shutdown server
srvWg.Wait() // wait for listeners on all ports to close
// check if all ports were covered
for _, port := range TestPorts {
if !portsMap[port] {
t.Fatal("missed port in test", port)
}
}
}