Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
fortytw2 committed May 13, 2017
1 parent 5550d63 commit 9a101ae
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Leaktest [![Build Status](https://travis-ci.org/fortytw2/leaktest.svg?branch=master)](https://travis-ci.org/fortytw2/leaktest)
Leaktest [![Build Status](https://travis-ci.org/fortytw2/leaktest.svg?branch=master)](https://travis-ci.org/fortytw2/leaktest) [![codecov](https://codecov.io/gh/fortytw2/leaktest/branch/master/graph/badge.svg)](https://codecov.io/gh/fortytw2/leaktest)
------

Refactored, tested variant of the goroutine leak detector found in both `net/http` tests and the `cockroachdb`
Expand All @@ -16,9 +16,11 @@ go get -u github.com/fortytw2/leaktest

### Example

This test fails, because it leaks a goroutine :o
These tests fail, because they leak a goroutine

```go
// Default "Check" will poll for 5 seconds to check that all
// goroutines are cleaned up
func TestPool(t *testing.T) {
defer leaktest.Check(t)()

Expand All @@ -28,6 +30,29 @@ func TestPool(t *testing.T) {
}
}()
}

// Helper function to timeout after X duration
func TestPoolTimeout(t *testing.T) {
defer leaktest.CheckTimeout(t, time.Second)()

go func() {
for {
time.Sleep(time.Second)
}
}()
}

// Use Go 1.7+ context.Context for cancellation
func TestPoolContext(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), time.Second)
defer leaktest.CheckContext(ctx, t)()

go func() {
for {
time.Sleep(time.Second)
}
}()
}
```


Expand Down

0 comments on commit 9a101ae

Please sign in to comment.