Skip to content
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

Add e2e orchestrator behavior tests on process maps and filters #1546

Merged
merged 2 commits into from
Dec 4, 2019
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
150 changes: 150 additions & 0 deletions e2e/orchestrator_event_filter_task_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package main

import (
"context"
"fmt"
"testing"
"time"

"github.com/mesg-foundation/engine/execution"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/process"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/protobuf/types"
"github.com/stretchr/testify/require"
)

func testOrchestratorEventFilterTask(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) {
return func(t *testing.T) {
var processHash hash.Hash

t.Run("create process", func(t *testing.T) {
respProc, err := client.ProcessClient.Create(context.Background(), &pb.CreateProcessRequest{
Key: "event-filter-task-process",
Nodes: []*process.Process_Node{
{
Type: &process.Process_Node_Event_{
Event: &process.Process_Node_Event{
Key: "n0",
InstanceHash: instanceHash,
EventKey: "test_event",
},
},
},
{
Type: &process.Process_Node_Filter_{
Filter: &process.Process_Node_Filter{
Key: "n1",
Conditions: []process.Process_Node_Filter_Condition{
{
Key: "msg",
Predicate: process.Process_Node_Filter_Condition_EQ,
Value: "shouldMatch",
},
},
},
},
},
{
Type: &process.Process_Node_Task_{
Task: &process.Process_Node_Task{
Key: "n2",
InstanceHash: instanceHash,
TaskKey: "task1",
},
},
},
},
Edges: []*process.Process_Edge{
{Src: "n0", Dst: "n1"},
{Src: "n1", Dst: "n2"},
},
})
require.NoError(t, err)
processHash = respProc.Hash
})
t.Run("pass filter", func(t *testing.T) {
t.Run("trigger process", func(t *testing.T) {
_, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{
InstanceHash: instanceHash,
Key: "test_event",
Data: &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StringValue{
StringValue: "shouldMatch",
},
},
"timestamp": {
Kind: &types.Value_NumberValue{
NumberValue: float64(time.Now().Unix()),
},
},
},
},
})
require.NoError(t, err)
})
t.Run("check in progress execution", func(t *testing.T) {
exec, err := executionStream.Recv()
require.NoError(t, err)
require.Equal(t, "task1", exec.TaskKey)
require.True(t, processHash.Equal(exec.ProcessHash))
require.Equal(t, execution.Status_InProgress, exec.Status)
require.Equal(t, "shouldMatch", exec.Inputs.Fields["msg"].GetStringValue())
})
t.Run("check completed execution", func(t *testing.T) {
exec, err := executionStream.Recv()
require.NoError(t, err)
require.Equal(t, "task1", exec.TaskKey)
require.True(t, processHash.Equal(exec.ProcessHash))
require.Equal(t, execution.Status_Completed, exec.Status)
require.Equal(t, "shouldMatch", exec.Outputs.Fields["msg"].GetStringValue())
require.NotEmpty(t, exec.Outputs.Fields["timestamp"].GetNumberValue())
})
})
t.Run("stop at filter", func(t *testing.T) {
t.Run("trigger process", func(t *testing.T) {
_, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{
InstanceHash: instanceHash,
Key: "test_event",
Data: &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StringValue{
StringValue: "shouldNOTMatch",
},
},
"timestamp": {
Kind: &types.Value_NumberValue{
NumberValue: float64(time.Now().Unix()),
},
},
},
},
})
require.NoError(t, err)
})
t.Run("wait 2 sec to check execution is not created", func(t *testing.T) {
recvC := make(chan error)
go func() {
// FIXME: this go routine is never garbage and the Recv may cause side effect if the stream is use later
exec, err := executionStream.Recv()
fmt.Println("received execution but should not", exec)
recvC <- err
}()
select {
case <-time.After(2 * time.Second):
return
case err := <-recvC:
require.NoError(t, err)
t.Fatal("should not received any execution")
}
})
})
t.Run("delete process", func(t *testing.T) {
_, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: processHash})
require.NoError(t, err)
})
}
}
109 changes: 109 additions & 0 deletions e2e/orchestrator_event_map_task_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"context"
"testing"
"time"

"github.com/mesg-foundation/engine/execution"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/process"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/protobuf/types"
"github.com/stretchr/testify/require"
)

func testOrchestratorEventMapTask(executionStream pb.Execution_StreamClient, instanceHash hash.Hash) func(t *testing.T) {
return func(t *testing.T) {
var processHash hash.Hash

t.Run("create process", func(t *testing.T) {
respProc, err := client.ProcessClient.Create(context.Background(), &pb.CreateProcessRequest{
Key: "event-map-task-process",
Nodes: []*process.Process_Node{
{
Type: &process.Process_Node_Event_{
Event: &process.Process_Node_Event{
Key: "n0",
InstanceHash: instanceHash,
EventKey: "test_event",
},
},
},
{
Type: &process.Process_Node_Map_{
Map: &process.Process_Node_Map{
Key: "n1",
Outputs: []*process.Process_Node_Map_Output{
{
Key: "msg",
Value: &process.Process_Node_Map_Output_Constant{
Constant: &types.Value{Kind: &types.Value_StringValue{StringValue: "itsAConstant"}},
},
},
},
},
},
},
{
Type: &process.Process_Node_Task_{
Task: &process.Process_Node_Task{
Key: "n2",
InstanceHash: instanceHash,
TaskKey: "task1",
},
},
},
},
Edges: []*process.Process_Edge{
{Src: "n0", Dst: "n1"},
{Src: "n1", Dst: "n2"},
},
})
require.NoError(t, err)
processHash = respProc.Hash
})
t.Run("trigger process", func(t *testing.T) {
_, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{
InstanceHash: instanceHash,
Key: "test_event",
Data: &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StringValue{
StringValue: "whatever",
},
},
"timestamp": {
Kind: &types.Value_NumberValue{
NumberValue: float64(time.Now().Unix()),
},
},
},
},
})
require.NoError(t, err)
})
t.Run("check in progress execution", func(t *testing.T) {
exec, err := executionStream.Recv()
require.NoError(t, err)
require.Equal(t, "task1", exec.TaskKey)
require.True(t, processHash.Equal(exec.ProcessHash))
require.Equal(t, execution.Status_InProgress, exec.Status)
require.Equal(t, "itsAConstant", exec.Inputs.Fields["msg"].GetStringValue())
})
t.Run("check completed execution", func(t *testing.T) {
exec, err := executionStream.Recv()
require.NoError(t, err)
require.Equal(t, "task1", exec.TaskKey)
require.True(t, processHash.Equal(exec.ProcessHash))
require.Equal(t, execution.Status_Completed, exec.Status)
require.Equal(t, "itsAConstant", exec.Outputs.Fields["msg"].GetStringValue())
require.NotEmpty(t, exec.Outputs.Fields["timestamp"].GetNumberValue())
})
t.Run("delete process", func(t *testing.T) {
_, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: processHash})
require.NoError(t, err)
})
}
}
Loading