pb/testing: triger more race condition by having the progress bar refresh more often
This commit is contained in:
parent
4cae413a29
commit
27f4b9e4a1
|
@ -35,16 +35,25 @@ type StackableProgressBar struct {
|
|||
items int32
|
||||
total int64
|
||||
|
||||
started bool
|
||||
started bool
|
||||
ConfigProgressbarFN func(*pb.ProgressBar)
|
||||
}
|
||||
|
||||
var _ ProgressBar = new(StackableProgressBar)
|
||||
|
||||
func (spb *StackableProgressBar) start() {
|
||||
spb.Bar.ProgressBar = pb.New(0)
|
||||
spb.Bar.ProgressBar.SetUnits(pb.U_BYTES)
|
||||
func defaultProgressbarConfigFn(bar *pb.ProgressBar) {
|
||||
bar.SetUnits(pb.U_BYTES)
|
||||
}
|
||||
|
||||
spb.Bar.ProgressBar.Start()
|
||||
func (spb *StackableProgressBar) start() {
|
||||
bar := pb.New(0)
|
||||
if spb.ConfigProgressbarFN == nil {
|
||||
spb.ConfigProgressbarFN = defaultProgressbarConfigFn
|
||||
}
|
||||
spb.ConfigProgressbarFN(bar)
|
||||
|
||||
bar.Start()
|
||||
spb.Bar.ProgressBar = bar
|
||||
spb.started = true
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,21 @@ package packer
|
|||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
)
|
||||
|
||||
func speedyProgressBar(bar *pb.ProgressBar) {
|
||||
bar.SetUnits(pb.U_BYTES)
|
||||
bar.SetRefreshRate(1 * time.Millisecond)
|
||||
bar.NotPrint = true
|
||||
}
|
||||
|
||||
func TestStackableProgressBar_race(t *testing.T) {
|
||||
bar := &StackableProgressBar{}
|
||||
bar := &StackableProgressBar{
|
||||
ConfigProgressbarFN: speedyProgressBar,
|
||||
}
|
||||
|
||||
start42Fn := func() { bar.Start(42) }
|
||||
finishFn := func() { bar.Finish() }
|
||||
|
@ -24,7 +35,7 @@ func TestStackableProgressBar_race(t *testing.T) {
|
|||
iterations int
|
||||
}{
|
||||
{"all public", fields{nil, []func(){start42Fn, finishFn, add21, add21}, finishFn}, 300},
|
||||
{"all public", fields{start42Fn, []func(){add21, add21}, finishFn}, 300},
|
||||
{"add", fields{start42Fn, []func(){add21}, finishFn}, 300},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in New Issue