Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests: fix tests
Signed-off-by: Zike Yang <zike@apache.org>
  • Loading branch information
RobertIndie committed Feb 25, 2024
commit ef205709853bdc7e22f1dcf524de2b6607773140
9 changes: 7 additions & 2 deletions fs/instance_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type FunctionInstanceImpl struct {

type CtxKey string

const (
CtxKeyFunctionName CtxKey = "function-name"
CtxKeyInstanceIndex CtxKey = "instance-index"
)

type DefaultInstanceFactory struct{}

func NewDefaultInstanceFactory() api.FunctionInstanceFactory {
Expand All @@ -50,8 +55,8 @@ func NewDefaultInstanceFactory() api.FunctionInstanceFactory {

func (f *DefaultInstanceFactory) NewFunctionInstance(definition *model.Function, sourceFactory contube.SourceTubeFactory, sinkFactory contube.SinkTubeFactory, index int32, logger *slog.Logger) api.FunctionInstance {
ctx, cancelFunc := context.WithCancel(context.Background())
ctx = context.WithValue(ctx, CtxKey("function-name"), definition.Name)
ctx = context.WithValue(ctx, CtxKey("instance-index"), index)
ctx = context.WithValue(ctx, CtxKeyFunctionName, definition.Name)
ctx = context.WithValue(ctx, CtxKeyInstanceIndex, index)
return &FunctionInstanceImpl{
ctx: ctx,
cancelFunc: cancelFunc,
Expand Down
8 changes: 4 additions & 4 deletions fs/instance_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func TestFunctionInstanceContextSetting(t *testing.T) {
t.Error("FunctionInstance should not be nil")
}

if ctxValue, ok := instance.Context().Value(CtxKey("function-name")).(string); !ok || ctxValue != definition.Name {
t.Errorf("Expected 'function-name' in ctx to be '%s'", definition.Name)
if ctxValue, ok := instance.Context().Value(CtxKeyFunctionName).(string); !ok || ctxValue != definition.Name {
t.Errorf("Expected '%s' in ctx to be '%s'", CtxKeyFunctionName, definition.Name)
}

if ctxValue, ok := instance.Context().Value(CtxKey("function-index")).(int32); !ok || ctxValue != index {
t.Errorf("Expected 'function-index' in ctx to be '%d'", index)
if ctxValue, ok := instance.Context().Value(CtxKey(CtxKeyInstanceIndex)).(int32); !ok || ctxValue != index {
t.Errorf("Expected '%s' in ctx to be '%d'", CtxKeyInstanceIndex, index)
}

}
1 change: 1 addition & 0 deletions fs/runtime/grpc/grpc_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (f *FunctionServerImpl) Process(stream proto.Function_ProcessServer) error
case <-instance.ctx.Done():
return nil
case e := <-errCh:
log.ErrorContext(stream.Context(), "error processing event", slog.Any("error", e))
return e
}
}
Expand Down