aboutsummaryrefslogtreecommitdiff
path: root/internal/progress/meter_test.go
blob: 8fa09973adbe8d037d5c17c4d87ccc01f63837ae (about) (plain) (blame)
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
38
39
40
41
42
43
package progress_test

import (
	"bytes"
	"strings"
	"sync"
	"testing"
	"time"

	"lindenii.org/go/furgit/internal/progress"
	"lindenii.org/go/lgo/iowrap"
)

func TestMeterConcurrentAdd(t *testing.T) {
	t.Parallel()

	var buf bytes.Buffer

	meter := progress.New(progress.Options{
		Writer: iowrap.NopFlush(&buf),
		Title:  "test",
		Total:  1000,
	})

	var wg sync.WaitGroup

	for range 10 {
		wg.Go(func() {
			for range 100 {
				meter.Add(1, 0)
				time.Sleep(time.Millisecond)
			}
		})
	}

	wg.Wait()

	meter.Stop("done")

	if got := buf.String(); !strings.Contains(got, "100% (1000/1000)") {
		t.Fatalf("final line = %q, want it to contain %q", got, "100% (1000/1000)")
	}
}