2021-03-15 17:30:18 +00:00
|
|
|
package output
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-03-16 17:07:22 +00:00
|
|
|
func TestProgressTimeoutDoesNotInc(t *testing.T) {
|
2021-05-03 16:41:52 +00:00
|
|
|
progress := NewProgress("loading", "loaded", false)
|
2021-03-15 17:30:18 +00:00
|
|
|
progress.Start()
|
2021-04-19 16:10:22 +00:00
|
|
|
progress.Inc()
|
2021-03-15 17:30:18 +00:00
|
|
|
progress.Stop() // should not hang
|
2021-04-19 16:10:22 +00:00
|
|
|
progress.Inc() // should restart progress and inc
|
|
|
|
assert.Equal(t, uint64(2), progress.Val())
|
|
|
|
assert.Equal(t, true, progress.started.Load())
|
|
|
|
|
|
|
|
progress.Stop()
|
|
|
|
assert.Equal(t, false, progress.started.Load())
|
2021-03-15 17:30:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 17:07:22 +00:00
|
|
|
func TestProgressTimeoutDoesNotHang(t *testing.T) {
|
2021-05-03 16:41:52 +00:00
|
|
|
progress := NewProgress("loading", "loaded", false)
|
2021-03-16 17:07:22 +00:00
|
|
|
progress.Start()
|
|
|
|
time.Sleep(progressTimeout)
|
|
|
|
for progress.started.Load() == true {
|
|
|
|
}
|
2021-04-19 16:10:22 +00:00
|
|
|
progress.Inc() // should not hang but inc
|
2021-03-16 17:07:22 +00:00
|
|
|
progress.Stop() // should not hang
|
2021-04-19 16:10:22 +00:00
|
|
|
assert.Equal(t, uint64(1), progress.Val())
|
2021-03-16 17:07:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:30:18 +00:00
|
|
|
func TestProgress(t *testing.T) {
|
2021-05-03 16:41:52 +00:00
|
|
|
progress := NewProgress("loading", "loaded", false)
|
2021-03-15 17:30:18 +00:00
|
|
|
progress.Start()
|
|
|
|
progress.Inc()
|
|
|
|
progress.Inc()
|
|
|
|
progress.Inc()
|
|
|
|
progress.Stop()
|
|
|
|
assert.Equal(t, uint64(3), progress.Val())
|
|
|
|
}
|