-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[CAPPL-735] Engine V2 execution phase (minimal impl) #17590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
36cbd6b
d631e98
876396c
ef982d4
152c4bc
8f03c3d
f9dfbb2
2ecd2be
b8c7529
be5ac26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package types | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
) | ||
|
||
// hash of (workflowID, triggerEventID) | ||
// TODO(CAPPL-838): improve for V2 | ||
func GenerateExecutionID(workflowID, triggerEventID string) (string, error) { | ||
s := sha256.New() | ||
_, err := s.Write([]byte(workflowID)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = s.Write([]byte(triggerEventID)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return hex.EncodeToString(s.Sum(nil)), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ func TestEngine_Init(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
module.EXPECT().Start().Once() | ||
module.EXPECT().SetCapabilityExecutor(mock.Anything).Return(nil).Once() | ||
module.EXPECT().Execute(matches.AnyContext, mock.Anything).Return(newTriggerSubs(0), nil).Once() | ||
capreg.EXPECT().LocalNode(matches.AnyContext).Return(capabilities.Node{}, nil).Once() | ||
require.NoError(t, engine.Start(t.Context())) | ||
|
@@ -62,6 +63,7 @@ func TestEngine_Start_RateLimited(t *testing.T) { | |
|
||
module := modulemocks.NewModuleV2(t) | ||
module.EXPECT().Start() | ||
module.EXPECT().SetCapabilityExecutor(mock.Anything).Return(nil) | ||
module.EXPECT().Execute(matches.AnyContext, mock.Anything).Return(newTriggerSubs(0), nil).Times(2) | ||
module.EXPECT().Close() | ||
capreg := regmocks.NewCapabilitiesRegistry(t) | ||
|
@@ -123,6 +125,7 @@ func TestEngine_TriggerSubscriptions(t *testing.T) { | |
|
||
module := modulemocks.NewModuleV2(t) | ||
module.EXPECT().Start() | ||
module.EXPECT().SetCapabilityExecutor(mock.Anything).Return(nil) | ||
module.EXPECT().Close() | ||
capreg := regmocks.NewCapabilitiesRegistry(t) | ||
capreg.EXPECT().LocalNode(matches.AnyContext).Return(capabilities.Node{}, nil) | ||
|
@@ -215,3 +218,61 @@ func newTriggerSubs(n int) *wasmpb.ExecutionResult { | |
}, | ||
} | ||
} | ||
|
||
func TestEngine_Execution(t *testing.T) { | ||
t.Parallel() | ||
|
||
module := modulemocks.NewModuleV2(t) | ||
module.EXPECT().Start() | ||
module.EXPECT().SetCapabilityExecutor(mock.Anything).Return(nil) | ||
module.EXPECT().Close() | ||
capreg := regmocks.NewCapabilitiesRegistry(t) | ||
capreg.EXPECT().LocalNode(matches.AnyContext).Return(capabilities.Node{}, nil) | ||
|
||
initDoneCh := make(chan error) | ||
subscribedToTriggersCh := make(chan []string, 1) | ||
executionFinishedCh := make(chan string) | ||
|
||
cfg := defaultTestConfig(t) | ||
cfg.Module = module | ||
cfg.CapRegistry = capreg | ||
cfg.Hooks = v2.LifecycleHooks{ | ||
OnInitialized: func(err error) { | ||
initDoneCh <- err | ||
}, | ||
OnSubscribedToTriggers: func(triggerIDs []string) { | ||
subscribedToTriggersCh <- triggerIDs | ||
}, | ||
OnExecutionFinished: func(executionID string) { | ||
executionFinishedCh <- executionID | ||
}, | ||
} | ||
|
||
t.Run("successful execution with no capability calls", func(t *testing.T) { | ||
engine, err := v2.NewEngine(t.Context(), cfg) | ||
require.NoError(t, err) | ||
module.EXPECT().Execute(matches.AnyContext, mock.Anything).Return(newTriggerSubs(1), nil).Once() | ||
trigger := capmocks.NewTriggerCapability(t) | ||
capreg.EXPECT().GetTrigger(matches.AnyContext, "id_0").Return(trigger, nil).Once() | ||
eventCh := make(chan capabilities.TriggerResponse) | ||
trigger.EXPECT().RegisterTrigger(matches.AnyContext, mock.Anything).Return(eventCh, nil).Once() | ||
trigger.EXPECT().UnregisterTrigger(matches.AnyContext, mock.Anything).Return(nil).Once() | ||
|
||
require.NoError(t, engine.Start(t.Context())) | ||
|
||
require.NoError(t, <-initDoneCh) // successful trigger registration | ||
require.Equal(t, []string{"id_0"}, <-subscribedToTriggersCh) | ||
|
||
module.EXPECT().Execute(matches.AnyContext, mock.Anything).Return(nil, nil).Once() | ||
eventCh <- capabilities.TriggerResponse{ | ||
Event: capabilities.TriggerEvent{ | ||
TriggerType: "[email protected]", | ||
ID: "event_012345", | ||
Payload: nil, | ||
}, | ||
} | ||
<-executionFinishedCh | ||
|
||
require.NoError(t, engine.Close()) | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit, could you add a second test that runs the test executable used to test the module? It'll ensure that there's no gaps to re-use it. I wouldn't remove this test, since it's easier to debug if things go wrong. I don't use config in that test yet, but it probably should opt to soon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is blocked until |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use
time.Duration
for these? Sheds the conversion on use, and makes the literals more readable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, for context, the other variables are already labeled Ms and uint32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pattern is used throughout the
capabilities
andgateway
packages, can move to a separate discussion because changing here makes this now inconsistent with other areas of the code.