Files
tasks/common/goro/goro_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

99 lines
2.0 KiB
Go

package goro_test
import (
"context"
"fmt"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/hanzoai/tasks/common/goro"
)
func blockOnCtxReturnErr(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
}
func blockOnCtxReturnNil(ctx context.Context) error {
<-ctx.Done()
return nil
}
func TestGoroParentTimeout(t *testing.T) {
pctx, pcancel := context.WithTimeout(context.TODO(), 5*time.Microsecond)
defer pcancel()
g := goro.NewHandle(pctx).Go(blockOnCtxReturnErr)
<-g.Done()
require.Equal(t, pctx.Err(), g.Err())
}
func TestGoroCancelParentCtx(t *testing.T) {
pctx, pcancel := context.WithCancel(context.TODO())
g := goro.NewHandle(pctx).Go(blockOnCtxReturnErr)
pcancel()
<-g.Done()
require.Equal(t, pctx.Err(), g.Err())
}
func TestGoroCancel(t *testing.T) {
pctx := context.Background()
g := goro.NewHandle(pctx).Go(blockOnCtxReturnErr)
g.Cancel()
<-g.Done()
require.ErrorIs(t, context.Canceled, g.Err())
require.Nil(t, pctx.Err())
}
func TestGoroMultiCancel(t *testing.T) {
g := goro.NewHandle(context.TODO()).Go(blockOnCtxReturnErr)
g.Cancel()
require.NotPanics(t, g.Cancel)
require.NotPanics(t, g.Cancel)
require.NotPanics(t, g.Cancel)
<-g.Done()
require.NotPanics(t, g.Cancel)
require.NotPanics(t, g.Cancel)
require.NotPanics(t, g.Cancel)
}
func TestGoroDoneNoErr(t *testing.T) {
g := goro.NewHandle(context.TODO()).Go(blockOnCtxReturnNil)
g.Cancel()
<-g.Done()
require.NoError(t, g.Err())
}
func TestGoroSimpleReturn(t *testing.T) {
g := goro.NewHandle(context.TODO()).Go(func(context.Context) error {
return nil
})
<-g.Done()
}
func TestGoroGoexit(t *testing.T) {
g := goro.NewHandle(context.TODO()).Go(func(context.Context) error {
runtime.Goexit()
return nil
})
<-g.Done()
}
func ExampleHandle() {
h := goro.NewHandle(context.Background()).Go(func(ctx context.Context) error {
<-ctx.Done()
fmt.Println("shutting down")
return ctx.Err()
})
fmt.Println(h.Err())
h.Cancel()
<-h.Done()
fmt.Println(h.Err())
// Output:
// <nil>
// shutting down
// context canceled
}