-
Notifications
You must be signed in to change notification settings - Fork 55
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
IWF-70: allow headers to be set in Interpreter Config #424
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a06f9c
allow headers to be set in Interpreter Config
samuel27m d325a39
adding integ tests
samuel27m 470b97a
Simplify workflow used for headers testing
samuel27m 9e723b4
Merge branch 'main' into config-headers
samuel27m a5da510
DefaultHeaders in plural
samuel27m af66ce5
renaming things to be more accurate
samuel27m a26b259
refactoring
samuel27m bb2ce57
removing empty file
samuel27m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package integ | ||
|
||
import ( | ||
"context" | ||
"github.com/indeedeng/iwf/integ/workflow/headers" | ||
"github.com/indeedeng/iwf/service/common/ptr" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/indeedeng/iwf/gen/iwfidl" | ||
"github.com/indeedeng/iwf/service" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHeadersWorkflowTemporal(t *testing.T) { | ||
if !*temporalIntegTest { | ||
t.Skip() | ||
} | ||
|
||
for i := 0; i < *repeatIntegTest; i++ { | ||
doTestWorkflowWithHeaders(t, service.BackendTypeTemporal, nil) | ||
smallWaitForFastTest() | ||
|
||
doTestWorkflowWithHeaders(t, service.BackendTypeTemporal, minimumContinueAsNewConfig(true)) | ||
smallWaitForFastTest() | ||
|
||
doTestWorkflowWithHeaders(t, service.BackendTypeTemporal, &iwfidl.WorkflowConfig{ | ||
DisableSystemSearchAttribute: iwfidl.PtrBool(true), | ||
}) | ||
smallWaitForFastTest() | ||
} | ||
} | ||
|
||
func TestHeadersWorkflowCadence(t *testing.T) { | ||
if !*cadenceIntegTest { | ||
t.Skip() | ||
} | ||
for i := 0; i < *repeatIntegTest; i++ { | ||
doTestWorkflowWithHeaders(t, service.BackendTypeCadence, nil) | ||
smallWaitForFastTest() | ||
doTestWorkflowWithHeaders(t, service.BackendTypeCadence, minimumContinueAsNewConfig(false)) | ||
smallWaitForFastTest() | ||
} | ||
} | ||
|
||
func doTestWorkflowWithHeaders(t *testing.T, backendType service.BackendType, config *iwfidl.WorkflowConfig) { | ||
// start test workflow server | ||
wfHandler := headers.NewHandler() | ||
closeFunc1 := startWorkflowWorker(wfHandler) | ||
defer closeFunc1() | ||
|
||
_, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ | ||
BackendType: backendType, | ||
DefaultHeaders: map[string]string{ | ||
headers.TestHeaderKey: headers.TestHeaderValue, | ||
}, | ||
}) | ||
defer closeFunc2() | ||
|
||
// start a workflow | ||
apiClient := iwfidl.NewAPIClient(&iwfidl.Configuration{ | ||
Servers: []iwfidl.ServerConfiguration{ | ||
{ | ||
URL: "http://localhost:" + testIwfServerPort, | ||
}, | ||
}, | ||
}) | ||
wfId := headers.WorkflowType + strconv.Itoa(int(time.Now().UnixNano())) | ||
wfInput := &iwfidl.EncodedObject{ | ||
Encoding: iwfidl.PtrString("json"), | ||
Data: iwfidl.PtrString("test data"), | ||
} | ||
req := apiClient.DefaultApi.ApiV1WorkflowStartPost(context.Background()) | ||
startReq := iwfidl.WorkflowStartRequest{ | ||
WorkflowId: wfId, | ||
IwfWorkflowType: headers.WorkflowType, | ||
WorkflowTimeoutSeconds: 100, | ||
IwfWorkerUrl: "http://localhost:" + testWorkflowServerPort, | ||
StartStateId: ptr.Any(headers.State1), | ||
StateInput: wfInput, | ||
WorkflowStartOptions: &iwfidl.WorkflowStartOptions{ | ||
WorkflowConfigOverride: config, | ||
}, | ||
} | ||
_, httpResp, err := req.WorkflowStartRequest(startReq).Execute() | ||
panicAtHttpError(err, httpResp) | ||
|
||
req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) | ||
_, httpResp2, err2 := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ | ||
WorkflowId: wfId, | ||
}).Execute() | ||
panicAtHttpError(err2, httpResp2) | ||
|
||
assertions := assert.New(t) | ||
|
||
history, _ := wfHandler.GetTestResult() | ||
assertions.Equalf(map[string]int64{ | ||
"S1_start": 1, | ||
"S1_decide": 1, | ||
}, history, "headers test fail, %v", history) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package headers | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/indeedeng/iwf/gen/iwfidl" | ||
"github.com/indeedeng/iwf/service" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
WorkflowType = "headers" | ||
State1 = "S1" | ||
|
||
TestHeaderKey = "integration-test-header" | ||
TestHeaderValue = "integration-test-value" | ||
) | ||
|
||
type handler struct { | ||
invokeHistory map[string]int64 | ||
} | ||
|
||
func NewHandler() *handler { | ||
return &handler{ | ||
invokeHistory: make(map[string]int64), | ||
} | ||
} | ||
|
||
// ApiV1WorkflowStartPost - for a workflow | ||
func (h *handler) ApiV1WorkflowStateStart(c *gin.Context) { | ||
headerValue := c.GetHeader(TestHeaderKey) | ||
if headerValue != TestHeaderValue { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "test header not found"}) | ||
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. I think we need to return here after |
||
return | ||
} | ||
|
||
var req iwfidl.WorkflowStateStartRequest | ||
if err := c.ShouldBindJSON(&req); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
log.Println("received state start request, ", req) | ||
|
||
if req.GetWorkflowType() == WorkflowType { | ||
// basic workflow go straight to decide methods without any commands | ||
if req.GetWorkflowStateId() == State1 { | ||
h.invokeHistory[req.GetWorkflowStateId()+"_start"]++ | ||
c.JSON(http.StatusOK, iwfidl.WorkflowStateStartResponse{ | ||
CommandRequest: &iwfidl.CommandRequest{ | ||
DeciderTriggerType: iwfidl.ALL_COMMAND_COMPLETED.Ptr(), | ||
}, | ||
}) | ||
return | ||
} | ||
} | ||
|
||
c.JSON(http.StatusBadRequest, struct{}{}) | ||
} | ||
|
||
func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) { | ||
headerValue := c.GetHeader(TestHeaderKey) | ||
if headerValue != TestHeaderValue { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": "test header not found"}) | ||
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. same here |
||
return | ||
} | ||
|
||
var req iwfidl.WorkflowStateDecideRequest | ||
if err := c.ShouldBindJSON(&req); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
log.Println("received state decide request, ", req) | ||
|
||
if req.GetWorkflowType() == WorkflowType { | ||
h.invokeHistory[req.GetWorkflowStateId()+"_decide"]++ | ||
if req.GetWorkflowStateId() == State1 { | ||
// go to S1 | ||
c.JSON(http.StatusOK, iwfidl.WorkflowStateDecideResponse{ | ||
StateDecision: &iwfidl.StateDecision{ | ||
NextStates: []iwfidl.StateMovement{ | ||
{ | ||
StateId: service.GracefulCompletingWorkflowStateId, | ||
StateInput: req.StateInput, | ||
}, | ||
}, | ||
}, | ||
}) | ||
return | ||
} | ||
} | ||
|
||
c.JSON(http.StatusBadRequest, struct{}{}) | ||
} | ||
|
||
func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) { | ||
return h.invokeHistory, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I saw that the previous implementation had integration tests that would check for the presence of the headers in every call, am I seeing that right? https://github.com/indeedeng/iwf/pull/356/files#diff-c3752f9aebfa9a670e62a5c0cc34c36bbfbfcbe849288ece0973806a34eac156R30-R33
I wanted to do something more flexible, where we would have a specific integration test for checking the headers passed in the configuration are being used, rather than having the route check it every time a call was made.
I do need some of your guidance here, I can't figure out how to do the integration tests with this approach.
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.
The headers will be used when making calls for stateAPI. So for a specific integ tests, you will still need to build out a router. But it will be cleaner to have that specific router, is that what you meant?
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.
That's what I'm thinking yes. Do you think that would be overkill for testing such a small feature?
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.
I think it’s a good idea. I have been lazy to do the right thing and the tests have become messy here
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.
I have created the tests now, I struggled a bit navigating through the existing ones trying to use one as a template. I'm sure the tests I created can be better. We can have a chat tomorrow about them and you can point me where I've gone wrong! Thanks in advance! 🙌
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.
Sounds good. I went through it and left you some comments already. and we can go through them later