jedib0t / go-pretty

Table-writer and more in golang!
MIT License
3.02k stars 119 forks source link

[progress] corner case: overall tracker disappears #245

Closed iyear closed 1 year ago

iyear commented 1 year ago

Describe the bug When Progress.updateFrequency and tracker completion time are both small and similar(especially equal), the overall tracker may disappears.

The reason for this (maybe): the overall tracker is determined to be done before the tracker is appended, but the tracker is successfully appended before the next render. Progress continues to run, but the overall tracker will never appear again.

In short: overall tracker is done, but new tracker is being added.

To Reproduce

package main

import (
    "fmt"
    "github.com/jedib0t/go-pretty/v6/progress"
    "strconv"
    "time"
)

func main() {
    pw := progress.NewWriter()
    pw.SetTrackerPosition(progress.PositionRight)
    pw.SetUpdateFrequency(time.Millisecond * 100)
    pw.Style().Colors = progress.StyleColorsExample
    pw.Style().Visibility.TrackerOverall = true

    go pw.Render()

    sem := make(chan struct{}, 3)

    for i := 0; i < 1000; i++ {
        sem <- struct{}{}
        go func(n int) {
            tracker := progress.Tracker{Message: strconv.Itoa(n)}
            pw.AppendTracker(&tracker)
            time.Sleep(100 * time.Millisecond)
            tracker.MarkAsDone()
            <-sem
        }(i)
    }

}

Expected behavior Overall tracker will still run in the case.

Software (please complete the following information):

jedib0t commented 1 year ago

Cut a tag for you with the fix: https://github.com/jedib0t/go-pretty/releases/tag/v6.4.3