Atlas › Test

TestWaitOnDifferentThread

Exact test identity: go.temporal.io/server/common/goro/TestWaitOnDifferentThread

Package
go.temporal.io/server/common/goro
Suite / test hierarchy
TestWaitOnDifferentThread
Test
TestWaitOnDifferentThread
Introduced at
TestWaitOnDifferentThread Frontier kind: Test frontier
Covered ranges
9
Covered lines
40
Covered files
3

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/goro/goro.go 18 covered LOC · 4 ranges

Open complete file

22 // the goroutine starts, which makes it possible for the goroutine to call
23 // Done() on itself (maybe indirectly) without a race condition.
24 > func NewHandle(ctx context.Context) *Handle { goro.go
25 > ctx, cancel := context.WithCancel(ctx)
26 > return &Handle{
27 > context: ctx,
28 > cancel: cancel,
29 > done: make(chan struct{}),
30 > }
31 > }
32
33 // Go launches the supplied function in its own goroutine. Go should be called
34 // exactly once on each *Handle.
35 > func (h *Handle) Go(f func(context.Context) error) *Handle { goro.go
36 > go func() {
37 > // use defer here so that the channel is closed even if the func calls
38 > // runtime.Goexit()
39 > defer close(h.done)
40 > if err := f(h.context); err != nil {
41 h.err.Store(err)
42 }
43 }()
44 > return h goro.go
45 }
46
49 // the Done() channel closing is the time taken by the goroutine to shut itself
50 // down.
51 > func (h *Handle) Done() <-chan struct{} { goro.go
52 > return h.done
53 > }
54
55 // Cancel requests that this goroutine stop by cancelling the associated context
go.temporal.io/server/common/goro/group.go 15 covered LOC · 4 ranges

Open complete file

27 // exit on their own (possibly never).
28 // NOTE: Errors returned by the supplied function are ignored.
29 > func (g *Group) Go(f func(ctx context.Context) error) { group.go
30 > g.initOnce.Do(g.init)
31 > g.wg.Go(func() {
32 > _ = f(g.ctx)
33 > })
34 }
35
36 // Cancel cancels the `context.Context` that was passed to all goroutines
37 // spawned via `Go` on this `Group`.
38 > func (g *Group) Cancel() { group.go
39 > g.initOnce.Do(g.init)
40 > g.cancel()
41 > }
42
43 // Wait blocks waiting for all goroutines spawned via `Go` on this `Group`
44 // instance to complete. If `Go` has not been called then this function returns
45 // immediately.
46 > func (g *Group) Wait() { group.go
47 > g.wg.Wait()
48 > }
49
50 > func (g *Group) init() { group.go
51 > g.ctx, g.cancel = context.WithCancel(context.Background())
52 > }
go.temporal.io/server/common/testing/parallelsuite/suite.go 7 covered LOC · 1 range

Open complete file

228 var inheritedMethods map[string]bool
229
230 > func init() { suite.go
231 > type ds struct{ Suite[*ds] }
232 > ptrType := reflect.TypeFor[*ds]()
233 > inheritedMethods = make(map[string]bool, ptrType.NumMethod())
234 > for method := range ptrType.Methods() {
235 > inheritedMethods[method.Name] = true
236 > }
237 }
238