forked from quic-go/quic-go
migrate the transport tests away from Ginkgo (#4783)
* migrate the transport tests away from Ginkgo * simplify mock net.PacketConn implementation
This commit is contained in:
@@ -4,13 +4,18 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
@@ -32,6 +37,28 @@ var _ = BeforeSuite(func() {
|
||||
log.SetOutput(io.Discard)
|
||||
})
|
||||
|
||||
// in the tests for the stream deadlines we set a deadline
|
||||
// and wait to make an assertion when Read / Write was unblocked
|
||||
// on the CIs, the timing is a lot less precise, so scale every duration by this factor
|
||||
func scaleDuration(t time.Duration) time.Duration {
|
||||
scaleFactor := 1
|
||||
if f, err := strconv.Atoi(os.Getenv("TIMESCALE_FACTOR")); err == nil { // parsing "" errors, so this works fine if the env is not set
|
||||
scaleFactor = f
|
||||
}
|
||||
if scaleFactor == 0 {
|
||||
panic("TIMESCALE_FACTOR is 0")
|
||||
}
|
||||
return time.Duration(scaleFactor) * t
|
||||
}
|
||||
|
||||
func newUPDConnLocalhost(t testing.TB) *net.UDPConn {
|
||||
t.Helper()
|
||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { conn.Close() })
|
||||
return conn
|
||||
}
|
||||
|
||||
func areServersRunning() bool {
|
||||
var b bytes.Buffer
|
||||
pprof.Lookup("goroutine").WriteTo(&b, 1)
|
||||
|
||||
Reference in New Issue
Block a user