MCPcopy Index your code
hub / github.com/kopia/kopia / TestEnqueueFrontAndProcess

Function TestEnqueueFrontAndProcess

internal/parallelwork/parallel_work_queue_test.go:16–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestEnqueueFrontAndProcess(t *testing.T) {
17 queue := parallelwork.NewQueue()
18
19 results := make(chan int, 3)
20
21 // Enqueue work items to the front of the queue
22 queue.EnqueueFront(context.Background(), func() error {
23 results <- 3
24 return nil
25 })
26 queue.EnqueueFront(context.Background(), func() error {
27 results <- 2
28 return nil
29 })
30 queue.EnqueueFront(context.Background(), func() error {
31 results <- 1
32 return nil
33 })
34
35 err := queue.Process(context.Background(), 2) // Use two workers
36 require.NoError(t, err)
37
38 close(results)
39
40 var sum int
41 for res := range results {
42 sum += res
43 }
44
45 require.Equal(t, 6, sum)
46}
47
48func TestEnqueueBackAndProcess(t *testing.T) {
49 queue := parallelwork.NewQueue()

Callers

nothing calls this directly

Calls 4

EnqueueFrontMethod · 0.95
ProcessMethod · 0.95
NewQueueFunction · 0.92
EqualMethod · 0.80

Tested by

no test coverage detected