Skip to content

Commit 7b730f8

Browse files
authored
Merge pull request #202 from babiel/data-races
fix: enable race detector for test and fix all detected races
2 parents f1b3580 + 2d34dad commit 7b730f8

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
run: go vet .
2424

2525
- name: Run go test
26-
run: go test -v -cover -vet=off .
26+
run: go test -race -v -cover -vet=off .

progressbar.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,8 @@ func NewOptions64(max int64, options ...Option) *ProgressBar {
394394
}
395395

396396
// if the render time interval attribute is set
397-
if b.config.spinnerChangeInterval != 0 {
397+
if b.config.spinnerChangeInterval != 0 && !b.config.invisible && b.config.ignoreLength {
398398
go func() {
399-
if b.config.invisible {
400-
return
401-
}
402-
if !b.config.ignoreLength {
403-
return
404-
}
405399
ticker := time.NewTicker(b.config.spinnerChangeInterval)
406400
defer ticker.Stop()
407401
for {

progressbar_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ func ExampleOptionShowIts_spinner() {
225225
bar.Reset()
226226
time.Sleep(1 * time.Second)
227227
bar.Add(5)
228+
bar.lock.Lock()
228229
s, err := vt.String()
230+
bar.lock.Unlock()
229231
if err != nil {
230232
log.Fatal(err)
231233
}
@@ -338,7 +340,9 @@ func ExampleOptionShowBytes_spinner() {
338340
// since 10 is the width and we don't know the max bytes
339341
// it will do a infinite scrolling.
340342
bar.Add(11)
343+
bar.lock.Lock()
341344
result, _ := virtualterm.Process(buf.String())
345+
bar.lock.Unlock()
342346
fmt.Print(result)
343347
// Output:
344348
// - (11 B/s) [1s]
@@ -505,7 +509,9 @@ func TestOptionSetElapsedTime_spinner(t *testing.T) {
505509
bar.Reset()
506510
time.Sleep(1 * time.Second)
507511
bar.Add(5)
512+
bar.lock.Lock()
508513
result, err := virtualterm.Process(buf.String())
514+
bar.lock.Unlock()
509515
result = strings.TrimSpace(result)
510516
if err != nil {
511517
t.Fatal(err)
@@ -965,7 +971,9 @@ func TestOptionSetSpinnerChangeInterval(t *testing.T) {
965971
OptionSetSpinnerChangeInterval(interval))
966972
bar.Add(1)
967973
for i := 0; i < 8; i++ {
974+
bar.lock.Lock()
968975
s, _ := vt.String()
976+
bar.lock.Unlock()
969977
s = strings.TrimSpace(s)
970978
actuals = append(actuals, s)
971979
// sleep 50 ms more to make sure to go to next interval each time
@@ -993,7 +1001,9 @@ func TestOptionSetSpinnerChangeIntervalZero(t *testing.T) {
9931001
}
9941002
for i := 0; i < 5; i++ {
9951003
bar.Add(1)
1004+
bar.lock.Lock()
9961005
s, _ := vt.String()
1006+
bar.lock.Unlock()
9971007
s = strings.TrimSpace(s)
9981008
}
9991009
for i := range actuals {

0 commit comments

Comments
 (0)