MCPcopy
hub / github.com/destel/rill / TestLoop

Function TestLoop

internal/core/loops_test.go:24–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestLoop(t *testing.T) {
25 th.TestBothOrderings(t, func(t *testing.T, ord bool) {
26 for _, n := range []int{1, 5} {
27 t.Run(th.Name("correctness", n), func(t *testing.T) {
28 in := th.FromRange(0, 20)
29 done := make(chan struct{})
30
31 var sum atomic.Int64
32
33 universalLoop(ord, in, done, n, func(x int, canWrite <-chan struct{}) {
34 <-canWrite
35 sum.Add(int64(x))
36 })
37
38 <-done
39 th.ExpectValue(t, sum.Load(), 19*20/2)
40 })
41
42 t.Run(th.Name("concurrency", n), func(t *testing.T) {
43 in := th.FromRange(0, 100)
44 out := make(chan int)
45
46 monitor := th.NewConcurrencyMonitor(1 * time.Second)
47
48 universalLoop(ord, in, out, n, func(x int, canWrite <-chan struct{}) {
49 monitor.Inc()
50 defer monitor.Dec()
51
52 <-canWrite
53
54 out <- x
55 })
56
57 Drain(out)
58
59 th.ExpectValue(t, monitor.Max(), n)
60 })
61
62 t.Run(th.Name("ordering", n), func(t *testing.T) {
63 in := th.FromRange(0, 20000)
64 out := make(chan int)
65
66 universalLoop(ord, in, out, n, func(x int, canWrite <-chan struct{}) {
67
68 <-canWrite
69
70 out <- x
71 })
72
73 outSlice := th.ToSlice(out)
74
75 if ord || n == 1 {
76 th.ExpectSorted(t, outSlice)
77 } else {
78 th.ExpectUnsorted(t, outSlice)
79 }
80
81 })

Callers

nothing calls this directly

Calls 13

IncMethod · 0.95
DecMethod · 0.95
MaxMethod · 0.95
TestBothOrderingsFunction · 0.92
NameFunction · 0.92
FromRangeFunction · 0.92
ExpectValueFunction · 0.92
NewConcurrencyMonitorFunction · 0.92
ToSliceFunction · 0.92
ExpectSortedFunction · 0.92
ExpectUnsortedFunction · 0.92
universalLoopFunction · 0.85

Tested by

no test coverage detected