Skip to content

Commit

Permalink
deflaking (#265)
Browse files Browse the repository at this point in the history
* remove logspam

* more logspam

* more logspam
  • Loading branch information
bramhaghosh committed Sep 28, 2018
1 parent f6bca0c commit 195b986
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 62 deletions.
5 changes: 4 additions & 1 deletion marbl/handler_test.go
Expand Up @@ -16,16 +16,19 @@ package marbl

import (
"fmt"
"golang.org/x/net/websocket"
"math/rand"
"net"
"net/http"
"strconv"
"testing"
"time"

"golang.org/x/net/websocket"
)

func TestStreamsInSentOrder(t *testing.T) {
//t.Skip("skipping test to deflake.")

l, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("net.Listen(): got %v, want no error", err)
Expand Down
35 changes: 0 additions & 35 deletions proxy_trafficshaping_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"net/http"
"net/http/httptest"
"net/http/httputil"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -63,9 +62,6 @@ func TestConstantThrottleAndClose(t *testing.T) {
tsh.ServeHTTP(rw, tsReq)
res := rw.Result()

body, _ := ioutil.ReadAll(res.Body)
t.Logf("%s", string(body))

if got, want := res.StatusCode, 200; got != want {
t.Fatalf("res.StatusCode: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -105,7 +101,6 @@ func TestConstantThrottleAndClose(t *testing.T) {
}

go func() {
t.Logf("starting %v", time.Now())
req, err := http.NewRequest("GET", "http://example/example", nil)
if err != nil {
t.Fatalf("http.NewRequest(): got %v, want no error", err)
Expand All @@ -121,7 +116,6 @@ func TestConstantThrottleAndClose(t *testing.T) {
}
body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
t.Logf("after reading all %v", time.Now())
c1 <- bodystr
}()

Expand Down Expand Up @@ -194,9 +188,6 @@ func TestSleepAndClose(t *testing.T) {
tsh.ServeHTTP(rw, tsReq)
res := rw.Result()

body, _ := ioutil.ReadAll(res.Body)
t.Logf("%s", string(body))

if got, want := res.StatusCode, 200; got != want {
t.Fatalf("res.StatusCode: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -236,7 +227,6 @@ func TestSleepAndClose(t *testing.T) {
}

go func() {
t.Logf("starting %v", time.Now())
req, err := http.NewRequest("GET", "http://example/example", nil)
if err != nil {
t.Fatalf("http.NewRequest(): got %v, want no error", err)
Expand All @@ -252,7 +242,6 @@ func TestSleepAndClose(t *testing.T) {
}
body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
t.Logf("after reading all %v", time.Now())
c1 <- bodystr
}()

Expand Down Expand Up @@ -317,9 +306,6 @@ func TestConstantThrottleAndCloseByteRange(t *testing.T) {
tsh.ServeHTTP(rw, tsReq)
res := rw.Result()

body, _ := ioutil.ReadAll(res.Body)
t.Logf("%s", string(body))

if got, want := res.StatusCode, 200; got != want {
t.Fatalf("res.StatusCode: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -360,7 +346,6 @@ func TestConstantThrottleAndCloseByteRange(t *testing.T) {
}

go func() {
t.Logf("starting %v", time.Now())
req, err := http.NewRequest("GET", "http://example/example", nil)
if err != nil {
t.Fatalf("http.NewRequest(): got %v, want no error", err)
Expand All @@ -377,9 +362,6 @@ func TestConstantThrottleAndCloseByteRange(t *testing.T) {

body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
dump, err := httputil.DumpResponse(res, true)
t.Logf("%s %d", dump, int64(len(dump)))
t.Logf("after reading all %v", time.Now())
c1 <- bodystr
}()

Expand Down Expand Up @@ -442,9 +424,6 @@ func TestMaxBandwidth(t *testing.T) {
tsh.ServeHTTP(rw, tsReq)
res := rw.Result()

body, _ := ioutil.ReadAll(res.Body)
t.Logf("%s", string(body))

if got, want := res.StatusCode, 200; got != want {
t.Fatalf("res.StatusCode: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -486,7 +465,6 @@ func TestMaxBandwidth(t *testing.T) {

for i := 0; i < numChannels; i++ {
go func(i int) {
t.Logf("%d starting %v", i, time.Now())
conn, err := net.Dial("tcp", l.Addr().String())
defer conn.Close()
if err != nil {
Expand All @@ -508,7 +486,6 @@ func TestMaxBandwidth(t *testing.T) {

body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
t.Logf("%d after reading all %v", i, time.Now())

if i != 0 {
<-channels[i-1]
Expand Down Expand Up @@ -585,9 +562,6 @@ func TestConcurrentResponseActions(t *testing.T) {
tsh.ServeHTTP(rw, tsReq)
res := rw.Result()

body, _ := ioutil.ReadAll(res.Body)
t.Logf("%s", string(body))

if got, want := res.StatusCode, 200; got != want {
t.Fatalf("res.StatusCode: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -628,7 +602,6 @@ func TestConcurrentResponseActions(t *testing.T) {
c2 := make(chan string)

go func() {
t.Logf("starting 1 %v", time.Now())
conn, err := net.Dial("tcp", l.Addr().String())
defer conn.Close()
if err != nil {
Expand All @@ -651,14 +624,10 @@ func TestConcurrentResponseActions(t *testing.T) {

body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
dump, err := httputil.DumpResponse(res, true)
t.Logf("%s %d", dump, int64(len(dump)))
t.Logf("1 after reading all %v", time.Now())
c1 <- bodystr
}()

go func() {
t.Logf("2 starting %v", time.Now())
conn, err := net.Dial("tcp", l.Addr().String())
defer conn.Close()
if err != nil {
Expand All @@ -680,9 +649,6 @@ func TestConcurrentResponseActions(t *testing.T) {

body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
dump, err := httputil.DumpResponse(res, true)
t.Logf("%s %d", dump, int64(len(dump)))
t.Logf("2 after reading all %v", time.Now())
c2 <- bodystr
}()

Expand All @@ -696,4 +662,3 @@ func TestConcurrentResponseActions(t *testing.T) {
t.Errorf("res.Body: got %s, want %s", bodystr2, want2)
}
}

3 changes: 1 addition & 2 deletions trafficshape/handler.go
Expand Up @@ -227,5 +227,4 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

rw.WriteHeader(http.StatusOK)
io.WriteString(rw, bodystr)
log.Infof("trafficshape: Configured from json %s", bodystr)
}
}
11 changes: 0 additions & 11 deletions trafficshape/handler_test.go
Expand Up @@ -17,7 +17,6 @@ package trafficshape
import (
"bytes"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -136,9 +135,6 @@ func TestHandlerIncorrectInputs(t *testing.T) {

h.ServeHTTP(rw, req)

body, _ := ioutil.ReadAll(rw.Result().Body)
t.Logf("%d\n %s", i+1, string(body))

if got := rw.Code; got != 400 {
t.Errorf("%d. rw.Code: got %d, want %d", i+1, got, 400)
}
Expand Down Expand Up @@ -167,9 +163,6 @@ func TestHandlerClear(t *testing.T) {

h.ServeHTTP(rw, req)

body, _ := ioutil.ReadAll(rw.Result().Body)
t.Logf("%s", string(body))

if got, want := rw.Code, 200; got != want {
t.Errorf(" rw.Code: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -244,9 +237,6 @@ func TestHandlerActions(t *testing.T) {

h.ServeHTTP(rw, req)

body, _ := ioutil.ReadAll(rw.Result().Body)
t.Logf("%d\n %s", i+1, string(body))

if got, want := rw.Code, 200; got != want {
t.Errorf("%d. rw.Code: got %d, want %d", i+1, got, want)
}
Expand All @@ -266,4 +256,3 @@ func TestHandlerActions(t *testing.T) {
}
}
}

7 changes: 2 additions & 5 deletions trafficshape/listener.go
Expand Up @@ -579,7 +579,6 @@ func (c *Conn) Write(b []byte) (int, error) {

return c.Context.GlobalBucket.FillThrottleLocked(func(rem int64) (int64, error) {
max = min(rem, max)
log.Debugf("Writing %d into connection", max)
n, err := c.Conn.Write(b[:max])

return int64(n), err
Expand All @@ -604,8 +603,6 @@ func (c *Conn) Write(b []byte) (int, error) {
c.Context.ByteOffset >= c.Context.NextActionInfo.ByteOffset {
// Note here, we check again that the url shape map is still valid and that the action still has
// a non zero count, since that could have been modified since the last time we checked.
log.Debugf("Performing action if there for regex %s byte offset %d",
c.Context.URLRegex, c.Context.ByteOffset)
ind := c.Context.NextActionInfo.Index
c.Shapes.RLock()
if !c.CheckExistenceAndValidity(c.Context.URLRegex) {
Expand All @@ -625,7 +622,7 @@ func (c *Conn) Write(b []byte) (int, error) {
switch action := actions[ind].(type) {
case *Halt:
d := action.Duration
log.Infof("trafficshape: Sleeping for time %d ms for urlregex %s at byte offset %d",
log.Debugf("trafficshape: Sleeping for time %d ms for urlregex %s at byte offset %d",
d, c.Context.URLRegex, c.Context.ByteOffset)
c.Shapes.M[c.Context.URLRegex].Unlock()
c.Shapes.RUnlock()
Expand Down Expand Up @@ -661,4 +658,4 @@ func (c *Conn) Write(b []byte) (int, error) {
func (c *Conn) sleepLatency() {
log.Debugf("trafficshape: simulating latency: %s", c.latency)
time.Sleep(c.latency)
}
}
8 changes: 0 additions & 8 deletions trafficshape/listener_test.go
Expand Up @@ -473,14 +473,10 @@ func TestActionsAndThrottles(t *testing.T) {

h.ServeHTTP(rw, req)

body, _ := ioutil.ReadAll(rw.Result().Body)
t.Logf("%d\n %s", i+1, string(body))

if got, want := rw.Code, 200; got != want {
t.Errorf("%d. rw.Code: got %d, want %d", i+1, got, want)
}

t.Logf("%d starting %v", i, time.Now())
conn, err := net.Dial("tcp", l.Addr().String())
defer conn.Close()
if err != nil {
Expand Down Expand Up @@ -526,9 +522,6 @@ func TestActionsAfterUpdatingCounts(t *testing.T) {

h.ServeHTTP(rw, req)

body, _ := ioutil.ReadAll(rw.Result().Body)
t.Logf("%s", string(body))

if got, want := rw.Code, 200; got != want {
t.Errorf("rw.Code: got %d, want %d", got, want)
}
Expand Down Expand Up @@ -573,4 +566,3 @@ func TestActionsAfterUpdatingCounts(t *testing.T) {
t.Errorf("NextActionInfo at %d got %+v, want %+v", 1015, got, want)
}
}

0 comments on commit 195b986

Please sign in to comment.