Skip to content

Instantly share code, notes, and snippets.

@MichaelSnowden
Created November 4, 2023 21:32
package main
import (
"context"
"os"
"github.com/pkg/errors"
"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common/primitives"
"go.temporal.io/server/internal/server"
"go.temporal.io/server/internal/servercli"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/temporal"
"go.uber.org/fx"
)
type (
faultyShardContextFactory struct {
base shard.ContextFactory
}
faultyShardContext struct {
shard.ControllableContext
}
faultyShardEngine struct {
shard.Engine
}
)
var sent = make(chan struct{}, 1)
func (f *faultyShardEngine) StartWorkflowExecution(
context.Context,
*historyservice.StartWorkflowExecutionRequest,
) (*historyservice.StartWorkflowExecutionResponse, error) {
select {
case sent <- struct{}{}:
return nil, errors.New("oopsie woopsie")
default:
return f.Engine.StartWorkflowExecution(context.Background(), &historyservice.StartWorkflowExecutionRequest{})
}
}
func (f faultyShardContext) GetEngine(ctx context.Context) (shard.Engine, error) {
engine, err := f.ControllableContext.GetEngine(ctx)
if err != nil {
return nil, err
}
return &faultyShardEngine{Engine: engine}, nil
}
func (f faultyShardContextFactory) CreateContext(shardID int32, closeCallback shard.CloseCallback) (shard.ControllableContext, error) {
shardContext, err := f.base.CreateContext(shardID, closeCallback)
if err != nil {
return nil, err
}
return &faultyShardContext{
ControllableContext: shardContext,
}, nil
}
func main() {
app := servercli.BuildApp(
temporal.WithInternalOptions(
server.WithServiceOptions(primitives.HistoryService,
fx.Decorate(func(shardContextFactory shard.ContextFactory) shard.ContextFactory {
return &faultyShardContextFactory{base: shardContextFactory}
}),
),
),
)
_ = app.Run(os.Args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment