Skip to content

Commit

Permalink
Fix go vet warnings in tests and up coverage to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
marusama committed Dec 13, 2017
1 parent e8e0bd7 commit 04c7e8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ BenchmarkPivotalGolangSemaphore_Acquire_Release_under_limit-4 100
BenchmarkPivotalGolangSemaphore_Acquire_Release_over_limit-4 10000 128890 ns/op 12800 B/op 200 allocs/op
```
You can rerun these benchmarks, just checkout `benchmarks` branch and do `go test -bench=. -benchmem ./bench/...`
You can rerun these benchmarks, just checkout `benchmarks` branch and run `go test -bench=. -benchmem ./bench/...`
24 changes: 16 additions & 8 deletions semaphore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ func TestSemaphore_TryAcquire_contention(t *testing.T) {

c := make(chan struct{})
wg := sync.WaitGroup{}
for i := 0; i < 100; i++ {
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
<-c
if sem.TryAcquire(1) {
sem.Release(1)
for j := 0; j < 10000; j++ {
if sem.TryAcquire(1) {
runtime.Gosched()
sem.Release(1)
}
}
wg.Done()
}()
Expand Down Expand Up @@ -244,7 +247,8 @@ func TestSemaphore_Acquire_Release_under_limit(t *testing.T) {

func TestSemaphore_Acquire_Release_under_limit_ctx_done(t *testing.T) {
sem := New(10)
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

c := make(chan struct{})
wg := sync.WaitGroup{}
Expand Down Expand Up @@ -300,7 +304,8 @@ func TestSemaphore_Acquire_Release_over_limit(t *testing.T) {

func TestSemaphore_Acquire_Release_over_limit_ctx_done(t *testing.T) {
sem := New(1)
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

c := make(chan struct{})
wg := sync.WaitGroup{}
Expand Down Expand Up @@ -509,7 +514,8 @@ func TestSemaphore_Acquire_Release_SetLimit_under_limit(t *testing.T) {

func TestSemaphore_Acquire_Release_SetLimit_under_limit_ctx_done(t *testing.T) {
sem := New(100)
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

c := make(chan struct{})
wg := sync.WaitGroup{}
Expand Down Expand Up @@ -610,7 +616,8 @@ func TestSemaphore_Acquire_Release_SetLimit_over_limit(t *testing.T) {

func TestSemaphore_Acquire_Release_SetLimit_over_limit_ctx_done(t *testing.T) {
sem := New(1)
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

c := make(chan struct{})
wg := sync.WaitGroup{}
Expand Down Expand Up @@ -711,7 +718,8 @@ func TestSemaphore_Acquire_Release_SetLimit_random_limit(t *testing.T) {

func TestSemaphore_Acquire_Release_SetLimit_random_limit_ctx_done(t *testing.T) {
sem := New(1)
ctx, _ := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

c := make(chan struct{})
wg := sync.WaitGroup{}
Expand Down

0 comments on commit 04c7e8f

Please sign in to comment.