2021-02-02 12:05:47 +01:00
|
|
|
package quicdialer_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/lucas-clemente/quic-go"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
|
2021-06-25 17:04:24 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSystemDialerSuccessWithReadWrite(t *testing.T) {
|
|
|
|
// This is the most common use case for collecting reads, writes
|
|
|
|
tlsConf := &tls.Config{
|
2021-06-14 16:59:24 +02:00
|
|
|
NextProtos: []string{"h3"},
|
2021-02-02 12:05:47 +01:00
|
|
|
ServerName: "www.google.com",
|
|
|
|
}
|
|
|
|
saver := &trace.Saver{}
|
2021-06-25 17:04:24 +02:00
|
|
|
systemdialer := &netxlite.QUICDialerQUICGo{
|
2021-06-25 16:20:08 +02:00
|
|
|
QUICListener: &quicdialer.QUICListenerSaver{
|
2021-06-25 17:04:24 +02:00
|
|
|
QUICListener: &netxlite.QUICListenerStdlib{},
|
2021-06-25 16:20:08 +02:00
|
|
|
Saver: saver,
|
|
|
|
},
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
_, err := systemdialer.DialContext(context.Background(), "udp",
|
|
|
|
"216.58.212.164:443", tlsConf, &quic.Config{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
ev := saver.Read()
|
|
|
|
if len(ev) < 2 {
|
|
|
|
t.Fatal("unexpected number of events")
|
|
|
|
}
|
|
|
|
last := len(ev) - 1
|
|
|
|
for idx := 1; idx < last; idx++ {
|
|
|
|
if ev[idx].Data == nil {
|
|
|
|
t.Fatal("unexpected Data")
|
|
|
|
}
|
|
|
|
if ev[idx].Duration <= 0 {
|
|
|
|
t.Fatal("unexpected Duration")
|
|
|
|
}
|
|
|
|
if ev[idx].Err != nil {
|
|
|
|
t.Fatal("unexpected Err")
|
|
|
|
}
|
|
|
|
if ev[idx].NumBytes <= 0 {
|
|
|
|
t.Fatal("unexpected NumBytes")
|
|
|
|
}
|
|
|
|
switch ev[idx].Name {
|
|
|
|
case errorx.ReadFromOperation, errorx.WriteToOperation:
|
|
|
|
default:
|
|
|
|
t.Fatal("unexpected Name")
|
|
|
|
}
|
|
|
|
if ev[idx].Time.Before(ev[idx-1].Time) {
|
2021-03-03 14:42:17 +01:00
|
|
|
t.Fatal("unexpected Time", ev[idx].Time, ev[idx-1].Time)
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|