Add delay to http server for proper testing

This commit is contained in:
Leonid Bugaev
2013-11-02 19:46:46 +01:00
parent dd806640f9
commit f7b3adc8cd
+4 -2
View File
@@ -6,11 +6,12 @@ import (
"net/http"
"sync"
"testing"
"time"
)
func startHTTP(cb func(*http.Request)) net.Listener {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cb(r)
go cb(r)
})
listener, _ := net.Listen("tcp", ":0")
@@ -63,7 +64,8 @@ func BenchmarkHTTPOutput(b *testing.B) {
headers := HTTPHeaders{HTTPHeader{"User-Agent", "Gor"}}
listener := startHTTP(func(req *http.Request) {
go wg.Done()
time.Sleep(50 * time.Millisecond)
wg.Done()
})
output := NewHTTPOutput(listener.Addr().String(), headers, "")