diff --git a/core/action/action.go b/core/action/action.go index a24ea4a1d..90abba49b 100644 --- a/core/action/action.go +++ b/core/action/action.go @@ -134,7 +134,6 @@ func (action *Action) Execute(pair *models.RequestResponsePair, journalIDChannel time.Sleep(time.Duration(200+action.DelayInMs) * time.Millisecond) journalID := <-journalIDChannel - close(journalIDChannel) log.Info("Journal ID received ", journalID) //if it is remote callback diff --git a/core/action/action_test.go b/core/action/action_test.go index df7d58084..dc962efcd 100644 --- a/core/action/action_test.go +++ b/core/action/action_test.go @@ -116,6 +116,7 @@ func Test_ExecuteLocalPostServeAction(t *testing.T) { newJournal := journal.NewJournal() journalIDChannel <- "demo-id" err = newAction.Execute(&originalPair, journalIDChannel, newJournal) + close(journalIDChannel) Expect(err).To(BeNil()) } @@ -136,6 +137,7 @@ func Test_ExecuteRemotePostServeAction(t *testing.T) { newJournal := journal.NewJournal() journalIDChannel <- "1" newAction, err := action.NewRemoteAction("test-callback", server.URL+"/process", 0) + close(journalIDChannel) Expect(err).To(BeNil()) err = newAction.Execute(&originalPair, journalIDChannel, newJournal) Expect(err).To(BeNil()) @@ -156,6 +158,7 @@ func Test_ExecuteRemotePostServeAction_WithUnReachableHost(t *testing.T) { newJournal := journal.NewJournal() journalIDChannel <- "1" err = newAction.Execute(&originalPair, journalIDChannel, newJournal) + close(journalIDChannel) Expect(err).NotTo(BeNil()) } diff --git a/core/hoverfly.go b/core/hoverfly.go index cb7a1786a..b523ff6f2 100644 --- a/core/hoverfly.go +++ b/core/hoverfly.go @@ -220,12 +220,11 @@ func (hf *Hoverfly) processRequest(req *http.Request) (*http.Response, chan stri } if result.PostServeActionInputDetails != nil { - - journalIDChannel := make(chan string, 1) if postServeAction, ok := hf.PostServeActionDetails.Actions[result.PostServeActionInputDetails.PostServeAction]; ok { + journalIDChannel := make(chan string, 1) go postServeAction.Execute(result.PostServeActionInputDetails.Pair, journalIDChannel, hf.Journal) + return result.Response, journalIDChannel } - return result.Response, journalIDChannel } return result.Response, nil diff --git a/core/hoverfly_service_test.go b/core/hoverfly_service_test.go index 75ab483fa..a422b7506 100644 --- a/core/hoverfly_service_test.go +++ b/core/hoverfly_service_test.go @@ -1371,6 +1371,12 @@ func TestHoverfly_GetPostServeActions(t *testing.T) { Expect(postServeActions).NotTo(BeNil()) Expect(postServeActions.Actions).To(HaveLen(2)) + Expect(postServeActions.Actions[0].ActionName).To(Equal("test-local-callback")) + Expect(postServeActions.Actions[0].Binary).To(Equal("python3")) + Expect(postServeActions.Actions[0].DelayInMs).To(Equal(1900)) + Expect(postServeActions.Actions[1].ActionName).To(Equal("test-remote-callback")) + Expect(postServeActions.Actions[1].Remote).To(Equal("http://localhost")) + Expect(postServeActions.Actions[1].DelayInMs).To(Equal(1800)) } func TestHoverfly_SetLocalPostServeAction(t *testing.T) { diff --git a/core/proxy.go b/core/proxy.go index 004256634..3f22f2e60 100644 --- a/core/proxy.go +++ b/core/proxy.go @@ -100,6 +100,7 @@ func NewProxy(hoverfly *Hoverfly) *goproxy.ProxyHttpServer { func sendJournalIDToPostServeAction(journalIDChannel chan string, id string) { if journalIDChannel != nil { journalIDChannel <- id + close(journalIDChannel) } }