diff --git a/progress_go1.7_test.go b/progress_go1.7_test.go new file mode 100644 index 0000000..e3607a0 --- /dev/null +++ b/progress_go1.7_test.go @@ -0,0 +1,39 @@ +//+build go1.7 +package mpb_test + +import ( + "context" + "fmt" + "math/rand" + "testing" + "time" + + "github.com/vbauerster/mpb" +) + +func TestWithContext(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + shutdown := make(chan struct{}) + p := mpb.New().WithContext(ctx).ShutdownNotify(shutdown) + numBars := 3 + + for i := 0; i < numBars; i++ { + name := fmt.Sprintf("Bar#%d:", i) + bar := p.AddBar(100).PrependName(name, len(name), 0) + + go func() { + for i := 0; i < 10000; i++ { + bar.Incr(1) + time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) + } + }() + } + + cancel() + + select { + case <-shutdown: + case <-time.After(500 * time.Millisecond): + t.Error("ProgressBar didn't stop") + } +} diff --git a/progress_test.go b/progress_test.go index 204811a..5e7a729 100644 --- a/progress_test.go +++ b/progress_test.go @@ -2,7 +2,6 @@ import ( "bytes" - "context" "fmt" "math/rand" "strings" @@ -99,33 +98,6 @@ p.Stop() } -func TestWithContext(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - shutdown := make(chan struct{}) - p := mpb.New().WithContext(ctx).ShutdownNotify(shutdown) - numBars := 3 - - for i := 0; i < numBars; i++ { - name := fmt.Sprintf("Bar#%d:", i) - bar := p.AddBar(100).PrependName(name, len(name), 0) - - go func() { - for i := 0; i < 10000; i++ { - bar.Incr(1) - time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond) - } - }() - } - - cancel() - - select { - case <-shutdown: - case <-time.After(500 * time.Millisecond): - t.Error("ProgressBar didn't stop") - } -} - func TestWithCancel(t *testing.T) { cancel := make(chan struct{}) shutdown := make(chan struct{})