feat: upgrade oohttp and propagate changes (#461)

Part of https://github.com/ooni/probe/issues/1506
This commit is contained in:
Simone Basso 2021-09-05 21:23:47 +02:00 committed by GitHub
commit b834af83ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 95 additions and 35 deletions

View file

@ -3,8 +3,11 @@ package netxlite
import (
"context"
"crypto/tls"
"errors"
"net"
"sync"
"testing"
"time"
"github.com/apex/log"
utls "gitlab.com/yawning/utls.git"
@ -45,3 +48,37 @@ func TestNewTLSHandshakerUTLSTypes(t *testing.T) {
t.Fatal("expected non-nil NewConn")
}
}
func TestUTLSConnHandshakeNotInterrupted(t *testing.T) {
ctx := context.Background()
conn := &utlsConn{
testableHandshake: func() error {
return nil
},
}
err := conn.HandshakeContext(ctx)
if err != nil {
t.Fatal(err)
}
}
func TestUTLSConnHandshakeInterrupted(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(1)
sigch := make(chan interface{})
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
conn := &utlsConn{
testableHandshake: func() error {
defer wg.Done()
<-sigch
return nil
},
}
err := conn.HandshakeContext(ctx)
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatal("not the error we expected", err)
}
close(sigch)
wg.Wait()
}