Skip to content

Commit

Permalink
defer cleanup plugins as rogue processes
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 25, 2024
1 parent 6193d2c commit a6c8e24
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 18 deletions.
3 changes: 1 addition & 2 deletions consumer/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (p *httpMockProvider) configure() error {
// and write the pact file if successful
func (p *httpMockProvider) ExecuteTest(t *testing.T, integrationTest func(MockServerConfig) error) error {
log.Println("[DEBUG] pact verify")
defer p.mockserver.CleanupPlugins()

var err error
if p.config.AllowedMockServerPorts != "" && p.config.Port <= 0 {
Expand Down Expand Up @@ -170,8 +171,6 @@ func (p *httpMockProvider) ExecuteTest(t *testing.T, integrationTest func(MockSe
return fmt.Errorf("pact validation failed: %+v", mismatches)
}

p.mockserver.CleanupPlugins()

return p.writePact()
}

Expand Down
2 changes: 2 additions & 0 deletions consumer/http_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ func (i *V4ResponseBuilder) BodyMatch(body interface{}) *V4ResponseBuilder {

// ExecuteTest runs the current test case against a Mock Service.
func (m *V4InteractionWithResponse) ExecuteTest(t *testing.T, integrationTest func(MockServerConfig) error) error {
defer m.provider.mockserver.CleanupPlugins()
return m.provider.ExecuteTest(t, integrationTest)
}

Expand Down Expand Up @@ -432,6 +433,7 @@ type V4InteractionWithPluginResponse struct {

// ExecuteTest runs the current test case against a Mock Service.
func (m *V4InteractionWithPluginResponse) ExecuteTest(t *testing.T, integrationTest func(MockServerConfig) error) error {
defer m.provider.mockserver.CleanupPlugins()
return m.provider.ExecuteTest(t, integrationTest)
}

Expand Down
3 changes: 3 additions & 0 deletions internal/native/message_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func TestGetPluginSyncMessageContentsAsBytes(t *testing.T) {
m := NewMessageServer("test-message-consumer", "test-message-provider")

// Protobuf plugin test
defer m.CleanupPlugins()
err := m.UsingPlugin("protobuf", "0.3.14")
assert.NoError(t, err)

Expand Down Expand Up @@ -248,6 +249,7 @@ func TestGetPluginAsyncMessageContentsAsBytes(t *testing.T) {
m := NewMessageServer("test-message-consumer", "test-message-provider")

// Protobuf plugin test
defer m.CleanupPlugins()
_ = m.UsingPlugin("protobuf", "0.3.14")

i := m.NewAsyncMessageInteraction("grpc interaction")
Expand Down Expand Up @@ -288,6 +290,7 @@ func TestGrpcPluginInteraction(t *testing.T) {
m := NewMessageServer("test-message-consumer", "test-message-provider")

// Protobuf plugin test
defer m.CleanupPlugins()
_ = m.UsingPlugin("protobuf", "0.3.14")

i := m.NewSyncMessageInteraction("grpc interaction")
Expand Down
1 change: 1 addition & 0 deletions internal/native/mock_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestPluginInteraction(t *testing.T) {
m := NewHTTPPact("test-plugin-consumer", "test-plugin-provider")

// Protobuf plugin test
defer m.CleanupPlugins()
_ = m.UsingPlugin("protobuf", "0.3.14")
m.WithSpecificationVersion(SPECIFICATION_VERSION_V4)

Expand Down
17 changes: 12 additions & 5 deletions internal/native/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ func TestVerifier_Verify(t *testing.T) {
res := v.Verify(args)

assert.Error(t, res)

// v.Shutdown()
})
}

func TestVerifier_NewForApplication(t *testing.T) {
v := NewVerifier("pact-go", "test")

assert.NotNil(t, v.handle)
v.Shutdown()
}

func TestVerifier_Execute(t *testing.T) {
v := NewVerifier("pact-go", "test")
err := v.Execute()
// func TestVerifier_Execute(t *testing.T) {
// v := NewVerifier("pact-go", "test")
// err := v.Execute()

assert.NoError(t, err)
}
// assert.NoError(t, err)

// v.Shutdown()
// }

func TestVerifier_Shutdown(t *testing.T) {
v := NewVerifier("pact-go", "test")
Expand All @@ -59,9 +64,11 @@ func TestVerifier_Shutdown(t *testing.T) {
func TestVerifier_SetProviderInfo(t *testing.T) {
v := NewVerifier("pact-go", "test")
v.SetProviderInfo("name", "http", "localhost", 1234, "/")
v.Shutdown()
}

func TestVerifier_SetConsumerFilters(t *testing.T) {
v := NewVerifier("pact-go", "test")
v.SetConsumerFilters([]string{"consumer1", "consumer2"})
v.Shutdown()
}
10 changes: 5 additions & 5 deletions message/v4/asynchronous_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type AsynchronousMessageWithPluginContents struct {
}

func (s *AsynchronousMessageWithPluginContents) ExecuteTest(t *testing.T, integrationTest func(m AsynchronousMessage) error) error {
s.rootBuilder.pact.messageserver.CleanupPlugins()
message, err := getAsynchronousMessageWithReifiedContents(s.rootBuilder.messageHandle, s.rootBuilder.Type)
if err != nil {
return err
Expand All @@ -106,8 +107,6 @@ func (s *AsynchronousMessageWithPluginContents) ExecuteTest(t *testing.T, integr
return err
}

s.rootBuilder.pact.messageserver.CleanupPlugins()

return s.rootBuilder.pact.messageserver.WritePactFile(s.rootBuilder.pact.config.PactDir, false)
}

Expand All @@ -133,13 +132,14 @@ type AsynchronousMessageWithTransport struct {
}

func (s *AsynchronousMessageWithTransport) ExecuteTest(t *testing.T, integrationTest func(tc TransportConfig, m AsynchronousMessage) error) error {
defer s.rootBuilder.pact.messageserver.CleanupPlugins()
defer s.rootBuilder.pact.messageserver.CleanupMockServer(s.transport.Port)

message, err := getAsynchronousMessageWithReifiedContents(s.rootBuilder.messageHandle, s.rootBuilder.Type)
if err != nil {
return err
}

defer s.rootBuilder.pact.messageserver.CleanupMockServer(s.transport.Port)

err = integrationTest(s.transport, message)

if err != nil {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (p *AsynchronousPact) AddAsynchronousMessage() *AsynchronousMessageBuilder
// request was provided.
func (p *AsynchronousPact) verifyMessageConsumerRaw(messageToVerify *AsynchronousMessageBuilder, handler AsynchronousConsumer) error {
log.Printf("[DEBUG] verify message")

defer p.messageserver.CleanupPlugins()
m, err := getAsynchronousMessageWithReifiedContents(messageToVerify.messageHandle, messageToVerify.Type)
if err != nil {
return err
Expand Down
12 changes: 7 additions & 5 deletions message/v4/synchronous_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ type SynchronousMessageWithPluginContents struct {
// Will cleanup interactions between tests within a suite
// and write the pact file if successful
func (m *SynchronousMessageWithPluginContents) ExecuteTest(t *testing.T, integrationTest func(m SynchronousMessage) error) error {
defer m.pact.mockserver.CleanupPlugins()
message, err := getSynchronousMessageWithContents(m.messageHandle)
if err != nil {
return err
Expand Down Expand Up @@ -246,13 +247,14 @@ type SynchronousMessageWithTransport struct {
}

func (s *SynchronousMessageWithTransport) ExecuteTest(t *testing.T, integrationTest func(tc TransportConfig, m SynchronousMessage) error) error {
defer s.pact.mockserver.CleanupPlugins()
defer s.pact.mockserver.CleanupMockServer(s.transport.Port)

message, err := getSynchronousMessageWithContents(s.messageHandle)
if err != nil {
return err
}

defer s.pact.mockserver.CleanupMockServer(s.transport.Port)

err = integrationTest(s.transport, message)

// matched := s.pact.mockserver.MockServerMatched(s.transport.Port)
Expand All @@ -266,9 +268,6 @@ func (s *SynchronousMessageWithTransport) ExecuteTest(t *testing.T, integrationT
if err != nil {
return err
}

s.pact.mockserver.CleanupPlugins()

return s.pact.mockserver.WritePactFileForServer(s.transport.Port, s.pact.config.PactDir, false)
}

Expand Down Expand Up @@ -322,6 +321,9 @@ func (m *SynchronousPact) AddSynchronousMessage(description string) *Unconfigure
// Will cleanup interactions between tests within a suite
// and write the pact file if successful
func (m *SynchronousMessageWithResponse) ExecuteTest(t *testing.T, integrationTest func(md SynchronousMessage) error) error {
// defer s.pact.mockserver.CleanupPlugins()
// defer s.pact.mockserver.CleanupMockServer(s.transport.Port)
defer m.pact.mockserver.CleanupPlugins()
message, err := getSynchronousMessageWithContents(m.messageHandle)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion provider/verify_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ type outputWriter interface {
}

func (v *VerifyRequest) Verify(handle *native.Verifier, writer outputWriter) error {
defer handle.Shutdown()
for _, transport := range v.Transports {
log.Println("[DEBUG] adding transport to verification", transport)
handle.AddTransport(transport.Protocol, transport.Port, transport.Path, transport.Scheme)
Expand All @@ -301,7 +302,6 @@ func (v *VerifyRequest) Verify(handle *native.Verifier, writer outputWriter) err
}

res := handle.Execute()
defer handle.Shutdown()

return res
}
Expand Down

0 comments on commit a6c8e24

Please sign in to comment.