Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable race detector for test and fix all detected races #202

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
run: go vet .

- name: Run go test
run: go test -v -cover -vet=off .
run: go test -race -v -cover -vet=off .
8 changes: 1 addition & 7 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,8 @@ func NewOptions64(max int64, options ...Option) *ProgressBar {
}

// if the render time interval attribute is set
if b.config.spinnerChangeInterval != 0 {
if b.config.spinnerChangeInterval != 0 && !b.config.invisible && b.config.ignoreLength {
go func() {
if b.config.invisible {
return
}
if !b.config.ignoreLength {
return
}
ticker := time.NewTicker(b.config.spinnerChangeInterval)
defer ticker.Stop()
for {
Expand Down
10 changes: 10 additions & 0 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ func ExampleOptionShowIts_spinner() {
bar.Reset()
time.Sleep(1 * time.Second)
bar.Add(5)
bar.lock.Lock()
s, err := vt.String()
bar.lock.Unlock()
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -338,7 +340,9 @@ func ExampleOptionShowBytes_spinner() {
// since 10 is the width and we don't know the max bytes
// it will do a infinite scrolling.
bar.Add(11)
bar.lock.Lock()
result, _ := virtualterm.Process(buf.String())
bar.lock.Unlock()
fmt.Print(result)
// Output:
// - (11 B/s) [1s]
Expand Down Expand Up @@ -505,7 +509,9 @@ func TestOptionSetElapsedTime_spinner(t *testing.T) {
bar.Reset()
time.Sleep(1 * time.Second)
bar.Add(5)
bar.lock.Lock()
result, err := virtualterm.Process(buf.String())
bar.lock.Unlock()
result = strings.TrimSpace(result)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -965,7 +971,9 @@ func TestOptionSetSpinnerChangeInterval(t *testing.T) {
OptionSetSpinnerChangeInterval(interval))
bar.Add(1)
for i := 0; i < 8; i++ {
bar.lock.Lock()
s, _ := vt.String()
bar.lock.Unlock()
s = strings.TrimSpace(s)
actuals = append(actuals, s)
// sleep 50 ms more to make sure to go to next interval each time
Expand Down Expand Up @@ -993,7 +1001,9 @@ func TestOptionSetSpinnerChangeIntervalZero(t *testing.T) {
}
for i := 0; i < 5; i++ {
bar.Add(1)
bar.lock.Lock()
s, _ := vt.String()
bar.lock.Unlock()
s = strings.TrimSpace(s)
}
for i := range actuals {
Expand Down
Loading