diff --git a/temporaltest/server.go b/temporaltest/server.go index 6d0d8da5..0f0193f5 100644 --- a/temporaltest/server.go +++ b/temporaltest/server.go @@ -39,9 +39,9 @@ func (ts *TestServer) fatal(err error) { ts.t.Fatal(err) } -// Worker registers and starts a Temporal worker on the specified task queue. -func (ts *TestServer) Worker(taskQueue string, registerFunc func(registry worker.Registry)) worker.Worker { - w := worker.New(ts.Client(), taskQueue, ts.defaultWorkerOptions) +// NewWorker registers and starts a Temporal worker on the specified task queue. +func (ts *TestServer) NewWorker(taskQueue string, registerFunc func(registry worker.Registry)) worker.Worker { + w := worker.New(ts.DefaultClient(), taskQueue, ts.defaultWorkerOptions) registerFunc(w) ts.workers = append(ts.workers, w) @@ -59,7 +59,7 @@ func (ts *TestServer) Worker(taskQueue string, registerFunc func(registry worker func (ts *TestServer) NewWorkerWithOptions(taskQueue string, registerFunc func(registry worker.Registry), opts worker.Options) worker.Worker { opts.WorkflowPanicPolicy = worker.FailWorkflow - w := worker.New(ts.Client(), taskQueue, opts) + w := worker.New(ts.DefaultClient(), taskQueue, opts) registerFunc(w) ts.workers = append(ts.workers, w) @@ -70,17 +70,17 @@ func (ts *TestServer) NewWorkerWithOptions(taskQueue string, registerFunc func(r return w } -// Client returns a Temporal client configured for making requests to the server. +// DefaultClient returns the default Temporal client configured for making requests to the server. // It is configured to use a pre-registered test namespace and will // be closed on TestServer.Stop. -func (ts *TestServer) Client() client.Client { +func (ts *TestServer) DefaultClient() client.Client { if ts.defaultClient == nil { ts.defaultClient = ts.NewClientWithOptions(ts.defaultClientOptions) } return ts.defaultClient } -// NewClientWithOptions returns a Temporal client configured for making requests to the server. +// NewClientWithOptions returns a new Temporal client configured for making requests to the server. // If no namespace option is set it will use a pre-registered test namespace. // The returned client will be closed on TestServer.Stop. func (ts *TestServer) NewClientWithOptions(opts client.Options) client.Client { @@ -161,3 +161,20 @@ func NewServer(opts ...TestServerOption) *TestServer { return &ts } + +// Worker registers and starts a Temporal worker on the specified task queue. +// +// Deprecated: Use function NewWorker() +func (ts *TestServer) Worker(taskQueue string, registerFunc func(registry worker.Registry)) worker.Worker { + return ts.NewWorker(taskQueue, registerFunc) +} + +// Client returns a Temporal client configured for making requests to the server. +// It is configured to use a pre-registered test namespace and will +// be closed on TestServer.Stop. +// +// Deprecated: Use function DefaultClient() +func (ts *TestServer) Client() client.Client { + return ts.DefaultClient() +} + diff --git a/temporaltest/server_test.go b/temporaltest/server_test.go index e52e6fb0..dfd08d62 100644 --- a/temporaltest/server_test.go +++ b/temporaltest/server_test.go @@ -23,10 +23,10 @@ var t *testing.T func ExampleNewServer_testWorker() { // Create test Temporal server and client ts := temporaltest.NewServer(temporaltest.WithT(t)) - c := ts.Client() + c := ts.DefaultClient() // Register a new worker on the `hello_world` task queue - ts.Worker("hello_world", func(registry worker.Registry) { + ts.NewWorker("hello_world", func(registry worker.Registry) { helloworld.RegisterWorkflowsAndActivities(registry) }) @@ -55,14 +55,14 @@ func ExampleNewServer_testWorker() { func TestNewServer(t *testing.T) { ts := temporaltest.NewServer(temporaltest.WithT(t)) - ts.Worker("hello_world", func(registry worker.Registry) { + ts.NewWorker("hello_world", func(registry worker.Registry) { helloworld.RegisterWorkflowsAndActivities(registry) }) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - wfr, err := ts.Client().ExecuteWorkflow( + wfr, err := ts.DefaultClient().ExecuteWorkflow( ctx, client.StartWorkflowOptions{TaskQueue: "hello_world"}, helloworld.Greet, @@ -99,7 +99,7 @@ func TestNewWorkerWithOptions(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - wfr, err := ts.Client().ExecuteWorkflow( + wfr, err := ts.DefaultClient().ExecuteWorkflow( ctx, client.StartWorkflowOptions{TaskQueue: "hello_world"}, helloworld.Greet, @@ -131,14 +131,14 @@ func TestDefaultWorkerOptions(t *testing.T) { ), ) - ts.Worker("hello_world", func(registry worker.Registry) { + ts.NewWorker("hello_world", func(registry worker.Registry) { helloworld.RegisterWorkflowsAndActivities(registry) }) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - wfr, err := ts.Client().ExecuteWorkflow( + wfr, err := ts.DefaultClient().ExecuteWorkflow( ctx, client.StartWorkflowOptions{TaskQueue: "hello_world"}, helloworld.Greet, @@ -166,7 +166,7 @@ func TestClientWithDefaultInterceptor(t *testing.T) { temporaltest.WithBaseClientOptions(opts), ) - ts.Worker( + ts.NewWorker( "hello_world", func(registry worker.Registry) { helloworld.RegisterWorkflowsAndActivities(registry) @@ -176,7 +176,7 @@ func TestClientWithDefaultInterceptor(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - wfr, err := ts.Client().ExecuteWorkflow( + wfr, err := ts.DefaultClient().ExecuteWorkflow( ctx, client.StartWorkflowOptions{TaskQueue: "hello_world"}, helloworld.Greet, @@ -200,10 +200,10 @@ func BenchmarkRunWorkflow(b *testing.B) { ts := temporaltest.NewServer() defer ts.Stop() - ts.Worker("hello_world", func(registry worker.Registry) { + ts.NewWorker("hello_world", func(registry worker.Registry) { helloworld.RegisterWorkflowsAndActivities(registry) }) - c := ts.Client() + c := ts.DefaultClient() for i := 0; i < b.N; i++ { func(b *testing.B) {