Skip to content

Instantly share code, notes, and snippets.

@pkieltyka
Created December 9, 2016 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkieltyka/a4bbf38318b321c3dd21504d26c73821 to your computer and use it in GitHub Desktop.
Save pkieltyka/a4bbf38318b321c3dd21504d26c73821 to your computer and use it in GitHub Desktop.
package middleware
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"sync"
"testing"
"github.com/pressly/chi"
)
func TestCloseNotify(t *testing.T) {
testContent := []byte("hi")
r := chi.NewRouter()
r.Use(CloseNotify)
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(testContent)
})
server := httptest.NewServer(r)
var wg sync.WaitGroup
for i := 0; i < 50; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
res, err := http.Get(server.URL)
assertNoError(t, err)
assertEqual(t, http.StatusOK, res.StatusCode)
buf, err := ioutil.ReadAll(res.Body)
assertNoError(t, err)
assertEqual(t, testContent, buf)
}(i)
}
wg.Wait()
server.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment