feat: port-filtering experiment (#891)

Part of https://github.com/ooni/probe/issues/2005
This commit is contained in:
DecFox 2022-09-14 23:24:43 +05:30 committed by GitHub
commit d6a362d96f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 452 additions and 0 deletions

View file

@ -0,0 +1,31 @@
package main
import (
"context"
"net"
"testing"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
func TestMainWorkingAsIntended(t *testing.T) {
srvTest = true // toggle to imply that we are running in test mode
go main()
dialer := netxlite.NewDialerWithoutResolver(model.DiscardLogger)
for _, port := range TestPorts {
<-srvTestChan
addr := net.JoinHostPort("127.0.0.1", port)
ctx := context.Background()
conn, err := dialer.DialContext(ctx, "tcp", addr)
if err != nil {
t.Fatal(err)
}
if conn == nil {
t.Fatal("expected non-nil conn")
}
conn.Close()
}
srvCancel() // shutdown server
srvWg.Wait() // wait for listeners on all ports to close
}