Skip to content

Commit a3638c1

Browse files
authored
progress: speed-up unit-tests (#377)
1 parent d562c3e commit a3638c1

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

progress/indicator_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ func TestIndeterminateIndicatorDominoes(t *testing.T) {
4646
}
4747

4848
out := strings.Builder{}
49-
f := IndeterminateIndicatorDominoes(time.Millisecond * 10)
49+
f := IndeterminateIndicatorDominoes(time.Microsecond * 10)
5050
for idx, expectedText := range expectedTexts {
5151
actual := f(maxLen)
5252
assert.Equal(t, 0, actual.Position, fmt.Sprintf("expectedTexts[%d]", idx))
5353
assert.Equal(t, expectedText, actual.Text, fmt.Sprintf("expectedTexts[%d]", idx))
5454
out.WriteString(fmt.Sprintf("`%v`,\n", actual.Text))
55-
time.Sleep(time.Millisecond * 10)
55+
time.Sleep(time.Microsecond * 10)
5656
}
5757
if t.Failed() {
5858
fmt.Println(out.String())
@@ -101,13 +101,13 @@ func TestIndeterminateIndicatorColoredDominoes(t *testing.T) {
101101
}
102102

103103
out := strings.Builder{}
104-
f := IndeterminateIndicatorColoredDominoes(time.Millisecond*10, text.FgHiGreen, text.FgHiBlack)
104+
f := IndeterminateIndicatorColoredDominoes(time.Microsecond*10, text.FgHiGreen, text.FgHiBlack)
105105
for idx, expectedText := range expectedTexts {
106106
actual := f(maxLen)
107107
assert.Equal(t, 0, actual.Position, fmt.Sprintf("expectedTexts[%d]", idx))
108108
assert.Equal(t, expectedText, actual.Text, fmt.Sprintf("expectedTexts[%d]", idx))
109109
out.WriteString(fmt.Sprintf("`%v`,\n", actual.Text))
110-
time.Sleep(time.Millisecond * 10)
110+
time.Sleep(time.Microsecond * 10)
111111
}
112112
if t.Failed() {
113113
fmt.Println(out.String())
@@ -122,11 +122,11 @@ func TestIndeterminateIndicatorMovingBackAndForth(t *testing.T) {
122122
0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1,
123123
}
124124

125-
f := IndeterminateIndicatorMovingBackAndForth(indicator, time.Millisecond*10)
125+
f := IndeterminateIndicatorMovingBackAndForth(indicator, time.Microsecond*10)
126126
for idx, expectedPosition := range expectedPositions {
127127
actual := f(maxLen)
128128
assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
129-
time.Sleep(time.Millisecond * 10)
129+
time.Sleep(time.Microsecond * 10)
130130
}
131131
}
132132

@@ -183,11 +183,11 @@ func TestIndeterminateIndicatorMovingLeftToRight(t *testing.T) {
183183
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
184184
}
185185

186-
f := IndeterminateIndicatorMovingLeftToRight(indicator, time.Millisecond*10)
186+
f := IndeterminateIndicatorMovingLeftToRight(indicator, time.Microsecond*10)
187187
for idx, expectedPosition := range expectedPositions {
188188
actual := f(maxLen)
189189
assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
190-
time.Sleep(time.Millisecond * 10)
190+
time.Sleep(time.Microsecond * 10)
191191
}
192192
}
193193

@@ -244,11 +244,11 @@ func TestIndeterminateIndicatorMovingRightToLeft(t *testing.T) {
244244
9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
245245
}
246246

247-
f := IndeterminateIndicatorMovingRightToLeft(indicator, time.Millisecond*10)
247+
f := IndeterminateIndicatorMovingRightToLeft(indicator, time.Microsecond*10)
248248
for idx, expectedPosition := range expectedPositions {
249249
actual := f(maxLen)
250250
assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
251-
time.Sleep(time.Millisecond * 10)
251+
time.Sleep(time.Microsecond * 10)
252252
}
253253
}
254254

@@ -331,12 +331,12 @@ func TestIndeterminateIndicatorPacMan(t *testing.T) {
331331
}
332332

333333
out := strings.Builder{}
334-
f := IndeterminateIndicatorPacMan(time.Millisecond * 10)
334+
f := IndeterminateIndicatorPacMan(time.Microsecond * 10)
335335
for idx, expectedText := range expectedTexts {
336336
actual := f(maxLen)
337337
assert.Equal(t, expectedText, actual.Text, fmt.Sprintf("expectedTexts[%d]", idx))
338338
out.WriteString(fmt.Sprintf("%#v,\n", actual.Text))
339-
time.Sleep(time.Millisecond * 10)
339+
time.Sleep(time.Microsecond * 10)
340340
}
341341
if t.Failed() {
342342
fmt.Println(out.String())
@@ -385,12 +385,12 @@ func TestIndeterminateIndicatorPacManChomp(t *testing.T) {
385385
}
386386

387387
out := strings.Builder{}
388-
f := IndeterminateIndicatorPacManChomp(time.Millisecond * 10)
388+
f := IndeterminateIndicatorPacManChomp(time.Microsecond * 10)
389389
for idx, expectedText := range expectedTexts {
390390
actual := f(maxLen)
391391
assert.Equal(t, expectedText, actual.Text, fmt.Sprintf("expectedTexts[%d]", idx))
392392
out.WriteString(fmt.Sprintf("%#v,\n", actual.Text))
393-
time.Sleep(time.Millisecond * 10)
393+
time.Sleep(time.Microsecond * 10)
394394
}
395395
if t.Failed() {
396396
fmt.Println(out.String())

progress/render_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
)
1313

1414
var (
15-
trackerIncrementInterval = time.Millisecond * 20
16-
renderUpdateFrequency = time.Millisecond * 10
17-
renderWaitTime = time.Millisecond * 20
15+
trackerIncrementInterval = time.Millisecond * 2
16+
renderUpdateFrequency = time.Microsecond * 500
17+
renderWaitTime = time.Millisecond * 5
1818
)
1919

2020
type outputWriter struct {
@@ -343,7 +343,7 @@ func TestProgress_RenderNeverStarted(t *testing.T) {
343343
time.Sleep(renderWaitTime)
344344
tr.MarkAsDone()
345345
pw.Stop()
346-
time.Sleep(time.Second)
346+
time.Sleep(renderWaitTime)
347347

348348
expectedOutPatterns := []*regexp.Regexp{
349349
regexp.MustCompile(`\s*\.\.\. {2}\?\?\? {2}\[\.{23}] \[0 in 0s]`),
@@ -365,9 +365,9 @@ func TestProgress_RenderNothing(t *testing.T) {
365365
pw.SetOutputWriter(&renderOutput)
366366

367367
go pw.Render()
368-
time.Sleep(time.Second)
368+
time.Sleep(renderWaitTime)
369369
pw.Stop()
370-
time.Sleep(time.Second)
370+
time.Sleep(renderWaitTime)
371371

372372
assert.Empty(t, renderOutput.String())
373373
}
@@ -790,7 +790,7 @@ func TestProgress_RenderSomeTrackers_WithOverallTracker_WithSpeedAndSpeedOverall
790790
regexp.MustCompile(`Calculating Total # 1 \.\.\. done! \[\d+\.\d+K in [\d.]+ms; \d+\.\d+K/s]`),
791791
regexp.MustCompile(`Downloading File # 2 \.\.\. done! \[\d+\.\d+KB in [\d.]+ms; \d+\.\d+KB/s]`),
792792
regexp.MustCompile(`Transferring Amount # 3 \.\.\. done! \[\$\d+\.\d+K in [\d.]+ms; \$\d+\.\d+K/s]`),
793-
regexp.MustCompile(`\[[.#]+] \[[\d.ms]+; ~ETA: [\d.ms]+]`),
793+
regexp.MustCompile(`\[[.#]+] \[[\d.ms]+; ~ETA: [\d.ms]+(; [\d.]+[\w/]+)?]`),
794794
regexp.MustCompile(`some information about something that happened at \d\d\d\d`),
795795
}
796796
out := renderOutput.String()

progress/tracker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestTracker_ETA(t *testing.T) {
11-
timeDelayUnit := time.Millisecond
11+
timeDelayUnit := time.Microsecond * 100
1212
timeDelay := timeDelayUnit * 25
1313

1414
tracker := Tracker{}

0 commit comments

Comments
 (0)