forked from gosuri/uiprogress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bar_test.go
37 lines (34 loc) · 633 Bytes
/
bar_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package uiprogress
import (
"math/rand"
"runtime"
"strings"
"sync"
"testing"
"time"
)
func TestBarPrepend(t *testing.T) {
b := NewBar(100)
b.PrependCompleted()
b.Set(50)
if !strings.Contains(b.String(), "50") {
t.Fatal("want", "50%", "in", b.String())
}
}
func TestBarIncr(t *testing.T) {
b := NewBar(10000)
runtime.GOMAXPROCS(runtime.NumCPU())
var wg sync.WaitGroup
for i := 0; i < 10000; i++ {
wg.Add(1)
go func() {
defer wg.Done()
b.Incr()
time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)))
}()
}
wg.Wait()
if b.Current() != 10000 {
t.Fatal("need", 10000, "got", b.Current())
}
}