Skip to content

Commit

Permalink
🐛 Handle motor error for progress bar (#841)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker authored Jan 26, 2023
1 parent bc421e0 commit 139c7e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cli/progress/multiprogress.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,26 @@ func (m *modelMultiProgress) updateOverallProgress() {
m.lock.Lock()
sumPercent := 0.0
validAssets := 0
erroredAssets := 0
for k := range m.Progress {
if k == overallProgressIndexName {
continue
}
errored := m.Progress[k].Errored
if errored {
erroredAssets++
continue
}
sumPercent += m.Progress[k].percent
validAssets++
}
overallPercent = math.Floor((sumPercent/float64(validAssets))*100) / 100
if validAssets > 0 {
overallPercent = math.Floor((sumPercent/float64(validAssets))*100) / 100
}
_, ok := m.Progress[overallProgressIndexName]
if ok && erroredAssets == len(m.Progress)-1 {
overallPercent = 1.0
}
m.Progress[overallProgressIndexName].percent = overallPercent
m.lock.Unlock()
return
Expand Down
23 changes: 23 additions & 0 deletions cli/progress/multiprogress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ func TestMultiProgressBarOnlyOneErrored(t *testing.T) {
assert.Contains(t, buf.String(), " X test1")
}

func TestMultiProgressBarAllErrored(t *testing.T) {
var in bytes.Buffer
var buf bytes.Buffer

progressBarElements := map[string]string{"1": "test1", "2": "test2", "3": "test3"}
multiprogress, err := newMultiProgressBarsMock(progressBarElements, []string{"1", "2", "3"}, &in, &buf)
require.NoError(t, err)

go func() {
// we need to wait for tea to start the Program, otherwise these would be no-ops
time.Sleep(1 * time.Millisecond)
// this should also end the tea program
multiprogress.Errored("1")
multiprogress.Errored("2")
multiprogress.Errored("3")
multiprogress.Close()
}()
err = multiprogress.Open()
require.NoError(t, err)
assert.Contains(t, buf.String(), " X test1")
assert.Contains(t, buf.String(), "100% overall 0/3 scanned 3/3 errored")
}

func TestMultiProgressBarLimitedNumber(t *testing.T) {
var in bytes.Buffer
var buf bytes.Buffer
Expand Down
1 change: 1 addition & 0 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (s *LocalScanner) RunAssetJob(job *AssetJob) {
connections, err := resolver.OpenAssetConnections(job.Ctx, job.Asset, job.GetCredential, job.DoRecord)
if err != nil {
job.Reporter.AddScanError(job.Asset, err)
job.ProgressReporter.Errored()
return
}

Expand Down

0 comments on commit 139c7e8

Please sign in to comment.