internal/tun2: speed up tests a little

This commit is contained in:
Cadey Ratio 2017-12-13 17:10:20 -08:00
parent ec8334d67b
commit 509c38b133
1 changed files with 16 additions and 10 deletions

View File

@ -174,21 +174,29 @@ func TestBackendRouting(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer l.Close()
go s.Listen(l, false) go s.Listen(l, false)
cases := []struct { cases := []struct {
name string name string
should200 bool wantStatusCode int
handler http.HandlerFunc handler http.HandlerFunc
}{ }{
{ {
name: "200 everything's okay", name: "200 everything's okay",
should200: true, wantStatusCode: http.StatusOK,
handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "HTTP 200, everything is okay :)", http.StatusOK) http.Error(w, "HTTP 200, everything is okay :)", http.StatusOK)
}), }),
}, },
{
name: "500 internal error",
wantStatusCode: http.StatusInternalServerError,
handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "HTTP 500, the world is on fire", http.StatusInternalServerError)
}),
},
} }
for _, cs := range cases { for _, cs := range cases {
@ -213,7 +221,7 @@ func TestBackendRouting(t *testing.T) {
go c.Connect(ctx) // TODO: fix the client library so this ends up actually getting cleaned up go c.Connect(ctx) // TODO: fix the client library so this ends up actually getting cleaned up
time.Sleep(time.Second) time.Sleep(125 * time.Millisecond)
req, err := http.NewRequest("GET", "http://cetacean.club/", nil) req, err := http.NewRequest("GET", "http://cetacean.club/", nil)
if err != nil { if err != nil {
@ -225,9 +233,9 @@ func TestBackendRouting(t *testing.T) {
t.Fatalf("error in doing round trip: %v", err) t.Fatalf("error in doing round trip: %v", err)
} }
if cs.should200 && resp.StatusCode != http.StatusOK { if cs.wantStatusCode != resp.StatusCode {
resp.Write(os.Stdout) resp.Write(os.Stdout)
t.Fatalf("got status %d instead of StatusOK", resp.StatusCode) t.Fatalf("got status %d instead of %d", resp.StatusCode, cs.wantStatusCode)
} }
}) })
} }
@ -258,8 +266,6 @@ func setupTestServer() (*Server, *mockStorage, net.Listener, error) {
} }
func BenchmarkHTTP200(b *testing.B) { func BenchmarkHTTP200(b *testing.B) {
b.Skip("this benchmark doesn't work yet")
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()