feat: add a simple dnsping experiment (#674)
See https://github.com/ooni/probe/issues/1987 (issue). See https://github.com/ooni/spec/pull/238 (impl). While there, fix the build for go1.18 by adding go1.18 specific tests. I was increasingly bothered by the build being red.
This commit is contained in:
@@ -98,11 +98,11 @@ func TestMeasurer_run(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("with local listener", func(t *testing.T) {
|
||||
srvrURL, err := startEchoServer()
|
||||
srvrURL, listener, err := startEchoServer()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
t.Log(srvrURL)
|
||||
defer listener.Close()
|
||||
meas, m, err := runHelper(srvrURL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -127,10 +127,10 @@ func TestMeasurer_run(t *testing.T) {
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// See https://github.com/lucas-clemente/quic-go/blob/v0.27.0/example/echo/echo.go#L34
|
||||
func startEchoServer() (string, error) {
|
||||
func startEchoServer() (string, quic.Listener, error) {
|
||||
listener, err := quic.ListenAddr("127.0.0.1:0", generateTLSConfig(), nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", nil, err
|
||||
}
|
||||
go echoWorkerMain(listener)
|
||||
URL := &url.URL{
|
||||
@@ -138,7 +138,7 @@ func startEchoServer() (string, error) {
|
||||
Host: listener.Addr().String(),
|
||||
Path: "/",
|
||||
}
|
||||
return URL.String(), nil
|
||||
return URL.String(), listener, nil
|
||||
}
|
||||
|
||||
// Worker used by startEchoServer to accept a quic connection.
|
||||
@@ -147,16 +147,17 @@ func startEchoServer() (string, error) {
|
||||
//
|
||||
// See https://github.com/lucas-clemente/quic-go/blob/v0.27.0/example/echo/echo.go#L34
|
||||
func echoWorkerMain(listener quic.Listener) {
|
||||
defer listener.Close()
|
||||
conn, err := listener.Accept(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
for {
|
||||
conn, err := listener.Accept(context.Background())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
stream, err := conn.AcceptStream(context.Background())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
stream.Close()
|
||||
}
|
||||
stream, err := conn.AcceptStream(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
stream.Close()
|
||||
}
|
||||
|
||||
// Setup a bare-bones TLS config for the server.
|
||||
|
||||
Reference in New Issue
Block a user