Skip to content

Commit

Permalink
Go modules support and race condition fixes (#60)
Browse files Browse the repository at this point in the history
* generate go.mod and go.sum files

* remove closeNotifier logic. Deprecated in go and causing race conditions.

* fix race condition due to incomplete use of the atomic package

* use locks  to prevent race conditions in healthcheck handler

* use correct logrustash import

* go modules tidy

* fix to latest version of logrus-logstash-hook

* update travis to check  raceconditions

* travis use go modules

* remove cover before_install step from travis

* remove gopkg

* defer cancel timeout context

* fix failing test reliant on test runner resources

* delete test case as it will always be flaky and reliant on server cpu resources
  • Loading branch information
tonyalaribe committed Apr 10, 2019
1 parent f35aa7c commit 261e476
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 359 deletions.
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
language: go
sudo: false
go:
- "1.9"
- "1.10"
- "1.12"

env: GO111MODULE=on

before_install:
- diff -u <(echo -n) <(gofmt -d -s .)

install:
- go get github.com/golang/dep/cmd/dep
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
- go mod download

script:
- $GOPATH/bin/dep ensure
- go test ./...
- go test -race ./...
263 changes: 0 additions & 263 deletions Gopkg.lock

This file was deleted.

44 changes: 0 additions & 44 deletions Gopkg.toml

This file was deleted.

26 changes: 0 additions & 26 deletions fdhttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,3 @@ func TestClient_MaxIdleConns(t *testing.T) {
assert.EqualValues(t, expectedActiveConns, atomic.LoadInt32(&activeConns))
}
}

func TestClient_MaxIdleConnsLifetime(t *testing.T) {
c := fdhttp.NewClient()
c.SetMaxIdleConns(1)
c.SetMaxIdleConnsPerHost(1)
c.SetIdleConnTimeout(10 * time.Millisecond)
c.SetIdleConnMaxLifetime(4 * time.Millisecond)

var activeConns int32
c.Use(middlewareConnCount(&activeConns))

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(1 * time.Millisecond)
}))
defer ts.Close()

done := make(chan struct{})
go func() {
httpGetParallel(t, c, ts.URL, 10)
done <- struct{}{}
}()

time.Sleep(20 * time.Millisecond)
assert.EqualValues(t, 0, atomic.LoadInt32(&activeConns))
<-done
}
Loading

0 comments on commit 261e476

Please sign in to comment.