schollz / schollz/progressbar

Failing test on non x86 architectures

Open
#103 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
4.7k
Forks
258
Avg merge
13h 31m
Merged PRs (30d)
1

Description

Hi @schollz

Thanks for your work on progressbar :)
However, while running tests on !x86 architectures, one of the test fails -- in particular this one:

=== RUN   ExampleOptionSetRenderBlankState
--- FAIL: ExampleOptionSetRenderBlankState (0.00s)
got:
0% |          |  [0s:-1s]
want:
0% |          |  [0s:0s]

On investigating further, it seems that the value of rightBrac is turning out to be negative. On further investigation, it is found that the value of the averageRate variable is "0" for this particular test, and hence a division by 0 is happening there, which results in a +Inf, now the rest of the operations convert this into 0s on x86 and -1 on rest arches.

Here's a sample code for instance:

package main

import
	(
		"time"
		"fmt"
	);

func main() {
	var rate float64 = 0
	max := 10
	min := 0
	res:= (time.Duration((1 / rate)*(float64(max) - float64(min))) * time.Second).String()
	fmt.Println(res)
}

Output on x86: 0s
Output on arm64/other arches: -1s

For now, I've applied this patch to force a 0s value if rightBrac is 0s:

--- a/progressbar.go
+++ b/progressbar.go
@@ -730,6 +730,11 @@
 	if c.predictTime {
 		leftBrac = (time.Duration(time.Since(s.startTime).Seconds()) * time.Second).String()
 		rightBrac = (time.Duration((1/averageRate)*(float64(c.max)-float64(s.currentNum))) * time.Second).String()
+		zerosec, _ := time.ParseDuration("0s")
+		rightsec, _ := time.ParseDuration(rightBrac)
+		if rightsec.Seconds() < zerosec.Seconds() {
+			rightBrac = "0s"
+		}
 	}
 
 	if c.fullWidth && !c.ignoreLength {

But I admit this might not be the best way to get around it. Please consider fixing this

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with progressbar.go around line 732 and run the ExampleOptionSetRenderBlankState test on a non-x86 architecture to reproduce the differing output. Trace the averageRate and rightBrac values involved in the predicted time calculation; done means the test consistently reports 0s rather than -1s across architectures.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.