remove weird test

This commit is contained in:
Fabricio 2018-12-03 22:00:26 -02:00
parent 9c760e0926
commit cd153c35fb

View file

@ -6,14 +6,10 @@ import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
"sort"
"strings"
"sync"
"testing"
"time"
)
// Test the reverse proxy handler
@ -169,58 +165,6 @@ func TestDumpResponseGzip(t *testing.T) {
}
}
func TestCaptureIDConcurrence(t *testing.T) {
// This test bothers me
// given
interactions := 1000
service := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
rw.WriteHeader(http.StatusOK)
}))
list := NewCaptureList(interactions)
capture := httptest.NewServer(NewRecorder(list, NewProxyHandler(service.URL)))
defer service.Close()
defer capture.Close()
// when
// Starts go routines so that captureID is incremented concurrently within NewProxyHandler()
wg := &sync.WaitGroup{}
wg.Add(interactions)
for i := 0; i < interactions; i++ {
go func() {
_, err := http.Get(capture.URL)
if err != nil {
t.Fatalf("Request Failed: %v", err)
}
wg.Done()
}()
}
wg.Wait()
// then
// Tests if captures IDs are sequential
captures := list.Items()
if len(captures) == 0 {
t.Fatalf("No captures found")
}
ids := make([]int, len(captures))
for i := 0; i < len(captures); i++ {
ids[i] = captures[i].ID
}
sort.Ints(ids)
for i := 0; i < len(captures); i++ {
if ids[i] != i+1 {
t.Fatalf("Capture IDs are not sequential")
}
}
}
func gzipStr(str string) string {
var buff bytes.Buffer
g := gzip.NewWriter(&buff)