forked from quic-go/quic-go
add support for the resumption test case
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -14,6 +15,8 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errUnsupported = errors.New("unsupported test case")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logFile, err := os.Create("/logs/log.txt")
|
logFile, err := os.Create("/logs/log.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -23,47 +26,80 @@ func main() {
|
|||||||
defer logFile.Close()
|
defer logFile.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(logFile)
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
urls := flag.Args()
|
|
||||||
|
|
||||||
testcase := os.Getenv("TESTCASE")
|
testcase := os.Getenv("TESTCASE")
|
||||||
|
if err := runTestcase(testcase); err != nil {
|
||||||
var useH3 bool
|
if err == errUnsupported {
|
||||||
switch testcase {
|
|
||||||
case "handshake", "transfer", "retry":
|
|
||||||
case "http3":
|
|
||||||
useH3 = true
|
|
||||||
default:
|
|
||||||
fmt.Printf("unsupported test case: %s\n", testcase)
|
fmt.Printf("unsupported test case: %s\n", testcase)
|
||||||
os.Exit(127)
|
os.Exit(127)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Downloading files failed: %s\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var roundTripper http.RoundTripper
|
func runTestcase(testcase string) error {
|
||||||
if useH3 {
|
flag.Parse()
|
||||||
|
urls := flag.Args()
|
||||||
|
|
||||||
|
switch testcase {
|
||||||
|
case "http3":
|
||||||
r := &http3.RoundTripper{
|
r := &http3.RoundTripper{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
roundTripper = r
|
return downloadFiles(r, urls)
|
||||||
} else {
|
case "handshake", "transfer", "retry":
|
||||||
|
case "resumption":
|
||||||
|
return runResumptionTest(urls)
|
||||||
|
default:
|
||||||
|
return errUnsupported
|
||||||
|
}
|
||||||
|
|
||||||
r := &http09.RoundTripper{
|
r := &http09.RoundTripper{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
roundTripper = r
|
return downloadFiles(r, urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runResumptionTest(urls []string) error {
|
||||||
|
if len(urls) < 2 {
|
||||||
|
return errors.New("expected at least 2 URLs")
|
||||||
|
}
|
||||||
|
csc := tls.NewLRUClientSessionCache(1)
|
||||||
|
|
||||||
|
// do the first transfer
|
||||||
|
r := &http09.RoundTripper{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
ClientSessionCache: csc,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if err := downloadFiles(r, urls[:1]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.Close()
|
||||||
|
|
||||||
|
// reestablish the connection, using the session ticket that the server (hopefully provided)
|
||||||
|
r = &http09.RoundTripper{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
ClientSessionCache: csc,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
return downloadFiles(r, urls[1:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadFiles(cl http.RoundTripper, urls []string) error {
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
for _, u := range urls {
|
for _, u := range urls {
|
||||||
url := u
|
url := u
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return downloadFile(roundTripper, url)
|
return downloadFile(cl, url)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if err := g.Wait(); err != nil {
|
return g.Wait()
|
||||||
fmt.Printf("Downloading files failed: %s\n", err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadFile(cl http.RoundTripper, url string) error {
|
func downloadFile(cl http.RoundTripper, url string) error {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch testcase {
|
switch testcase {
|
||||||
case "handshake", "transfer":
|
case "handshake", "transfer", "resumption":
|
||||||
err = runHTTP09Server(quicConf)
|
err = runHTTP09Server(quicConf)
|
||||||
case "retry":
|
case "retry":
|
||||||
// By default, quic-go performs a Retry on every incoming connection.
|
// By default, quic-go performs a Retry on every incoming connection.
|
||||||
|
|||||||
Reference in New Issue
Block a user