Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added test for client concurrency
  • Loading branch information
SlyMarbo committed Mar 3, 2015
1 parent af1ca6a commit fc862fd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions client_test.go
Expand Up @@ -8,9 +8,12 @@ import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"

"github.com/SlyMarbo/spdy"
Expand Down Expand Up @@ -53,6 +56,40 @@ func TestClientHead(t *testing.T) {
}
}

func TestClientInGoroutines(t *testing.T) {
ts := newServer(robotsTxtHandler)
ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0) // ignore messages
defer ts.Close()

client := spdy.NewClient(false)

var wg sync.WaitGroup

for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
var b []byte
r, err := client.Get(ts.URL)
if err == nil {
b, err = pedanticReadAll(r.Body)
r.Body.Close()
}
if err != nil {
// We've turned off InsecureSkipVerify, so
// ignore bad cert warnings.
if !strings.Contains(err.Error(), "certificate signed by unknown authority") {
t.Error(err)
}
} else if s := string(b); !strings.HasPrefix(s, "User-agent:") {
t.Errorf("Incorrect page body (did not begin with User-agent): %q", s)
}
}()
}

wg.Wait()
}

// FIXME: Fails
// func TestClientRedirects(t *testing.T) {
// defer afterTest(t)
Expand Down

0 comments on commit fc862fd

Please sign in to comment.