MCPcopy
hub / github.com/jesseduffield/lazygit / TestAsyncHandler

Function TestAsyncHandler

pkg/tasks/async_handler_test.go:12–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestAsyncHandler(t *testing.T) {
13 wg := sync.WaitGroup{}
14 wg.Add(2)
15
16 onWorker := func(f func(gocui.Task) error) {
17 go func() { _ = f(gocui.NewFakeTask()) }()
18 }
19 handler := NewAsyncHandler(onWorker)
20 handler.onReject = func() {
21 wg.Done()
22 }
23
24 result := 0
25
26 wg2 := sync.WaitGroup{}
27 wg2.Add(1)
28
29 handler.Do(func() func() {
30 wg2.Wait()
31 return func() {
32 fmt.Println("setting to 1")
33 result = 1
34 }
35 })
36 handler.Do(func() func() {
37 return func() {
38 fmt.Println("setting to 2")
39 result = 2
40 wg.Done()
41 wg2.Done()
42 }
43 })
44
45 wg.Wait()
46
47 assert.EqualValues(t, 2, result)
48}

Callers

nothing calls this directly

Calls 6

DoMethod · 0.95
NewFakeTaskFunction · 0.92
NewAsyncHandlerFunction · 0.85
DoneMethod · 0.65
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected