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

IWF-343: Fix concurrent write panic for parallel test #545

Merged
merged 5 commits into from
Feb 13, 2025
Merged
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
25 changes: 20 additions & 5 deletions integ/workflow/parallel/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/indeedeng/iwf/service"
"log"
"net/http"
"sync"
"testing"
"time"
)
Expand Down Expand Up @@ -52,12 +53,12 @@ const (
)

type handler struct {
invokeHistory map[string]int64
invokeHistory sync.Map
}

func NewHandler() common.WorkflowHandler {
return &handler{
invokeHistory: make(map[string]int64),
invokeHistory: sync.Map{},
}
}

Expand All @@ -71,7 +72,11 @@ func (h *handler) ApiV1WorkflowStateStart(c *gin.Context, t *testing.T) {
log.Println("received state start request, ", req)

if req.GetWorkflowType() == WorkflowType {
h.invokeHistory[req.GetWorkflowStateId()+"_start"]++
if value, ok := h.invokeHistory.Load(req.GetWorkflowStateId() + "_start"); ok {
h.invokeHistory.Store(req.GetWorkflowStateId()+"_start", value.(int64)+1)
} else {
h.invokeHistory.Store(req.GetWorkflowStateId()+"_start", int64(1))
}
Copy link
Member Author

@samuel27m samuel27m Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't reproduce the issue described in #472, but I can see that this issue could very well happen due to the nature of the Workflow in this test.

Looking for opinions on if this is something that we need to polish a bit more, and if we want to make all our other tests also use sync.Map for storing the current invokeHistory in the integration tests to avoid this issue in the future too

Copy link
Member Author

@samuel27m samuel27m Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed today, I have now applied the same logic now for all the tests. i.e. all tests now use sync.Map which can be written to concurrently


// Go straight to the decide methods without any commands
c.JSON(http.StatusOK, iwfidl.WorkflowStateStartResponse{
Expand All @@ -94,7 +99,12 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) {
log.Println("received state decide request, ", req)

if req.GetWorkflowType() == WorkflowType {
h.invokeHistory[req.GetWorkflowStateId()+"_decide"]++
if value, ok := h.invokeHistory.Load(req.GetWorkflowStateId() + "_decide"); ok {
h.invokeHistory.Store(req.GetWorkflowStateId()+"_decide", value.(int64)+1)
} else {
h.invokeHistory.Store(req.GetWorkflowStateId()+"_decide", int64(1))
}

var nextStates []iwfidl.StateMovement
switch req.GetWorkflowStateId() {
case State1:
Expand Down Expand Up @@ -185,5 +195,10 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context, t *testing.T) {
}

func (h *handler) GetTestResult() (map[string]int64, map[string]interface{}) {
return h.invokeHistory, nil
result := make(map[string]int64)
h.invokeHistory.Range(func(key, value interface{}) bool {
result[key.(string)] = value.(int64)
return true
})
return result, nil
}