MCPcopy Create free account
hub / github.com/pion/ice / TestRunReturnsErrClosedWhenLoopClosing

Function TestRunReturnsErrClosedWhenLoopClosing

internal/taskloop/taskloop_test.go:15–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestRunReturnsErrClosedWhenLoopClosing(t *testing.T) {
16 loop := New(func() {})
17
18 blockStarted := make(chan struct{})
19 releaseBlock := make(chan struct{})
20 go func() {
21 _ = loop.Run(context.Background(), func(context.Context) {
22 close(blockStarted)
23 <-releaseBlock
24 })
25 }()
26 <-blockStarted
27
28 var secondRan atomic.Bool
29 errCh := make(chan error, 1)
30 go func() {
31 errCh <- loop.Run(context.Background(), func(context.Context) {
32 secondRan.Store(true)
33 })
34 }()
35
36 time.Sleep(10 * time.Millisecond)
37
38 closeDone := make(chan struct{})
39 go func() {
40 loop.Close()
41 close(closeDone)
42 }()
43
44 select {
45 case err := <-errCh:
46 assert.ErrorIs(t, err, ErrClosed)
47 case <-time.After(time.Second):
48 assert.Fail(t, "Run did not return after loop close")
49 }
50
51 close(releaseBlock)
52
53 select {
54 case <-closeDone:
55 case <-time.After(time.Second):
56 assert.Fail(t, "Close did not return")
57 }
58
59 assert.False(t, secondRan.Load(), "second task should not excute after loop is closed")
60}

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
RunMethod · 0.80
StoreMethod · 0.80
LoadMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…