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
parent 18a9523496
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

@ -31,7 +31,7 @@ func shutdown(ctx context.Context, l net.Listener) {
}
// TODO(DecFox): Add the ability of an echo service to generate some traffic
func handleConnetion(ctx context.Context, conn net.Conn) {
func handleConnection(ctx context.Context, conn net.Conn) {
defer conn.Close()
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
@ -48,10 +48,10 @@ func listenTCP(ctx context.Context, port string) {
for {
conn, err := listener.Accept()
if err != nil {
log.Infof("listener unable to accept connections on port%s", port)
log.Infof("listener unable to accept connections on port: %s", port)
return
}
go handleConnetion(ctx, conn)
go handleConnection(ctx, conn)
}
}

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)
}
}
}