temporaltest

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestServer

type TestServer struct {
	// contains filtered or unexported fields
}

A TestServer is a Temporal server listening on a system-chosen port on the local loopback interface, for use in end-to-end tests.

func NewServer

func NewServer(opts ...TestServerOption) *TestServer

NewServer starts and returns a new TestServer.

If not specifying the WithT option, the caller should execute Stop when finished to close the server and release resources.

Example (TestWorker)
package main

import (
	"context"
	"fmt"
	"testing"

	"go.temporal.io/sdk/client"
	"go.temporal.io/sdk/worker"

	"github.com/hishamk/temporalite/internal/examples/helloworld"
	"github.com/hishamk/temporalite/temporaltest"
)

// to be used in example code
var t *testing.T

func main() {
	// Create test Temporal server and client
	ts := temporaltest.NewServer(temporaltest.WithT(t))
	c := ts.DefaultClient()

	// Register a new worker on the `hello_world` task queue
	ts.NewWorker("hello_world", func(registry worker.Registry) {
		helloworld.RegisterWorkflowsAndActivities(registry)
	})

	// Start test workflow
	wfr, err := c.ExecuteWorkflow(
		context.Background(),
		client.StartWorkflowOptions{TaskQueue: "hello_world"},
		helloworld.Greet,
		"world",
	)
	if err != nil {
		t.Fatal(err)
	}

	// Get workflow result
	var result string
	if err := wfr.Get(context.Background(), &result); err != nil {
		t.Fatal(err)
	}

	// Print result
	fmt.Println(result)
}
Output:

Hello world

func (*TestServer) DefaultClient

func (ts *TestServer) DefaultClient() client.Client

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 (*TestServer) NewClientWithOptions

func (ts *TestServer) NewClientWithOptions(opts client.Options) client.Client

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 (*TestServer) NewWorker

func (ts *TestServer) NewWorker(taskQueue string, registerFunc func(registry worker.Registry)) worker.Worker

NewWorker registers and starts a Temporal worker on the specified task queue.

func (*TestServer) NewWorkerWithOptions

func (ts *TestServer) NewWorkerWithOptions(taskQueue string, registerFunc func(registry worker.Registry), opts worker.Options) worker.Worker

NewWorkerWithOptions returns a Temporal worker on the specified task queue.

WorkflowPanicPolicy is always set to worker.FailWorkflow so that workflow executions fail fast when workflow code panics or detects non-determinism.

func (*TestServer) Stop

func (ts *TestServer) Stop()

Stop closes test clients and shuts down the server.

type TestServerOption

type TestServerOption interface {
	// contains filtered or unexported methods
}

func WithBaseClientOptions

func WithBaseClientOptions(o client.Options) TestServerOption

WithBaseClientOptions configures options for the default clients and workers connected to the test server.

func WithBaseWorkerOptions

func WithBaseWorkerOptions(o worker.Options) TestServerOption

With WithBaseWorkerOptions configures default options for workers connected to the test server.

WorkflowPanicPolicy is always set to worker.FailWorkflow so that workflow executions fail fast when workflow code panics or detects non-determinism.

func WithT

func WithT(t *testing.T) TestServerOption

WithT directs all worker and client logs to the test logger.

If this option is specified, then server will automatically be stopped when the test completes.

func WithTemporaliteOptions

func WithTemporaliteOptions(options ...temporalite.ServerOption) TestServerOption

WithTemporaliteOptions provides the ability to use additional Temporalite options, including temporalite.WithUpstreamOptions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL