fix more race conditions
This commit is contained in:
parent
27f4b9e4a1
commit
25775cd266
|
@ -93,17 +93,17 @@ func (spb *StackableProgressBar) Finish() {
|
|||
spb.mtx.Lock()
|
||||
defer spb.mtx.Unlock()
|
||||
|
||||
spb.items--
|
||||
if spb.items == 0 {
|
||||
if spb.items < 0 {
|
||||
spb.items--
|
||||
}
|
||||
if spb.items == 0 && spb.Bar.ProgressBar != nil {
|
||||
// slef cleanup
|
||||
spb.Bar.ProgressBar.Finish()
|
||||
spb.Bar.ProgressBar = nil
|
||||
spb.started = false
|
||||
spb.total = 0
|
||||
return
|
||||
}
|
||||
if spb.Bar.ProgressBar != nil {
|
||||
spb.prefix()
|
||||
}
|
||||
}
|
||||
|
||||
// BasicProgressBar is packer's basic progress bar.
|
||||
|
|
|
@ -12,6 +12,7 @@ func speedyProgressBar(bar *pb.ProgressBar) {
|
|||
bar.SetUnits(pb.U_BYTES)
|
||||
bar.SetRefreshRate(1 * time.Millisecond)
|
||||
bar.NotPrint = true
|
||||
bar.Format("[\x00=\x00>\x00-\x00]")
|
||||
}
|
||||
|
||||
func TestStackableProgressBar_race(t *testing.T) {
|
||||
|
@ -36,6 +37,7 @@ func TestStackableProgressBar_race(t *testing.T) {
|
|||
}{
|
||||
{"all public", fields{nil, []func(){start42Fn, finishFn, add21, add21}, finishFn}, 300},
|
||||
{"add", fields{start42Fn, []func(){add21}, finishFn}, 300},
|
||||
{"add start", fields{start42Fn, []func(){start42Fn, add21}, finishFn}, 300},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in New Issue