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

Can't run consumer tests via command line on remote server #233

Closed
billysoomro opened this issue Feb 17, 2020 · 14 comments
Closed

Can't run consumer tests via command line on remote server #233

billysoomro opened this issue Feb 17, 2020 · 14 comments

Comments

@billysoomro
Copy link

billysoomro commented Feb 17, 2020

Hi,

I can run my pact consumer tests via command line locally but I can't seem to run the same command on my remote server and keep getting the following error:

**The connection to 'localhost' failed.
Error: ConnectionRefused (0x274d).
System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:9222

Stack Trace:
at PactNet.Mocks.MockHttpService.AdminHttpClient.SendAdminHttpRequest[T](HttpVerb method, String path, T requestContent, IDictionary`2 headers) in C:\projects\pact-net\PactNet\Mocks\MockHttpService\AdminHttpClient.cs:line 80
at PactNet.Mocks.MockHttpService.MockProviderService.SendAdminHttpRequest(HttpVerb method, String path) in C:\projects\pact-net\PactNet\Mocks\MockHttpService\MockProviderService.cs:line 130
at PactNet.PactBuilder.Build() in C:\projects\pact-net\PactNet\PactBuilder.cs:line 115

----- Inner Stack Trace -----
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
----- Inner Stack Trace -----
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)**

There are no firewall or anti-virus rules preventing the app as far as I can see, I've even opened up the port in question via inbound and outbound firewall rules but to no avail. The app is simply not able to open a port (9222 or any other port number I specify) for some reason to start making http requests to the mock provider client to create pact files.

Is there anything else that could be preventing these tests from running?

Thanks,
Billy

@neilcampbell
Copy link
Member

Yeah I'm not too sure what's going on. It could be something to do with permission of the user running the tests? Can you try elevating the user permissions? Seems like the mock server cannot start for some reason.

@bethesque
Copy link
Member

Is the mock service bound to 0.0.0.0 or localhost?

@billysoomro
Copy link
Author

Is the mock service bound to 0.0.0.0 or localhost?

Hi, I've coded it to run on localhost like=> http://localhost:9222

@billysoomro
Copy link
Author

Yeah I'm not too sure what's going on. It could be something to do with permission of the user running the tests? Can you try elevating the user permissions? Seems like the mock server cannot start for some reason.

Hi, I've tried running the tests via powershell admin and get the same sort errors, additionally I'm logged onto the server using an admin account but I'll play around the permissions to see if I can get them running.

@bethesque
Copy link
Member

Could you try starting up on of these one line servers on your remote host, and see if you can make a windows-equivalent-of-curl request to it?

@billysoomro
Copy link
Author

Could you try starting up on of these one line servers on your remote host, and see if you can make a windows-equivalent-of-curl request to it?

Hi Beth,

I was able to create a small server using node running port 8000 to display a simple web page. So what does this mean for my pact tests?

Thanks,
Billy

@bethesque
Copy link
Member

So what does this mean for my pact tests?

It means that you have enough permissions to start a service on a port 8000 (so presumably 9222 is also fine), and you're not blocked from contacting that service by anything internally.

Were you able to access that web page from a shell within the remote host?

So, I guess there are a few possibilities.

  1. The mock service is not starting properly.
  2. The mock service is starting but it's not on an interface that allows another connection from within the same host to be made to it (not sure how this would happen).
  3. It's starting but for some reason it's not on the expected port.
  4. It's starting, but the .net client code is not able to connect to it for some other reason.

Can you think of some experiments to try and work out which of these (or any other) is likely? Eg. if the mock service is starting, then you should see some logs somewhere.

One approach might be to download the mock service from https://github.com/pact-foundation/pact-ruby-standalone/releases and start it up manually on the remote host on port 9222 and then see if you can make an HTTP request to it.

@AshleyPoole
Copy link

@bethesque @neilcampbell i'm also getting the same issue.

I'm able to start up other web servers including Kestrel and they work fine, but for some reason the mock server doesn't start when running on Windows 10 in a .NET Core 3.1 project. I get the same exception as @billysoomro.

I've disabling the firewall as well but to no avail. It works using the Pactnet.Linux and Pactnet.OSX providers on their respected OS's, just not on Windows using Pactnet.Windows. I've also ensured I have long file path supported enabled, as the file paths are over the 260 default limit.

I've tried running fiddler and I see the request being made but the server isn't responding and I cannot access it myself, nor see the started HTTP server log line for it, so i'm sure it's not getting started.

As per above, I've downloaded the standalone server and it starts successfully using the bat file and responds to requests.

Any help you could provide would be appreciated!

@AshleyPoole
Copy link

AshleyPoole commented Apr 4, 2020

@bethesque @neilcampbell I've been able to replicate the issue with the samples in this project. If you update sample projects in this repo to netcoreapp3.1 they then fail with the same issues as being described. Hopefully this is useful information to work off.

Here's the stack trace from one of the sample tests that fail when using dotnet core 3.1.

  X Consumer.Tests.EventsApiConsumerTests.CreateEvent_WhenCalledWithEvent_Succeeds [1ms]
  Error Message:
   System.AggregateException : One or more errors occurred. (One or more errors occurred. (No connection could be made because the target machine actively refused it.)) (The following constructor parameters did not have matching fixture data: ConsumerEventApiPact data)
---- System.AggregateException : One or more errors occurred. (No connection could be made because the target machine actively refused it.)
-------- System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it.
------------ System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
---- The following constructor parameters did not have matching fixture data: ConsumerEventApiPact data
  Stack Trace:

----- Inner Stack Trace #1 (System.AggregateException) -----
   at PactNet.Mocks.MockHttpService.Host.RubyHttpHost.Start() in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\Mocks\MockHttpService\Host\RubyHttpHost.cs:line 66
   at PactNet.Mocks.MockHttpService.MockProviderService.Start() in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\Mocks\MockHttpService\MockProviderService.cs:line 137
   at PactNet.PactBuilder.MockService(Int32 port, JsonSerializerSettings jsonSerializerSettings, Boolean enableSsl, IPAddress host, String sslCert, String sslKey) in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\PactBuilder.cs:line 101
   at PactNet.PactBuilder.MockService(Int32 port, Boolean enableSsl, IPAddress host, String sslCert, String sslKey) in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\PactBuilder.cs:line 70
   at Consumer.Tests.ConsumerEventApiPact..ctor() in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\Samples\EventApi\Consumer.Tests\ConsumerEventApiPact.cs:line 28
----- Inner Stack Trace -----
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
----- Inner Stack Trace -----
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----

@adamh-brum
Copy link

@bethesque @neilcampbell I've been able to replicate the issue with the samples in this project. If you update sample projects in this repo to netcoreapp3.1 they then fail with the same issues as being described. Hopefully this is useful information to work off.

Here's the stack trace from one of the sample tests that fail when using dotnet core 3.1.

  X Consumer.Tests.EventsApiConsumerTests.CreateEvent_WhenCalledWithEvent_Succeeds [1ms]
  Error Message:
   System.AggregateException : One or more errors occurred. (One or more errors occurred. (No connection could be made because the target machine actively refused it.)) (The following constructor parameters did not have matching fixture data: ConsumerEventApiPact data)
---- System.AggregateException : One or more errors occurred. (No connection could be made because the target machine actively refused it.)
-------- System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it.
------------ System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it.
---- The following constructor parameters did not have matching fixture data: ConsumerEventApiPact data
  Stack Trace:

----- Inner Stack Trace #1 (System.AggregateException) -----
   at PactNet.Mocks.MockHttpService.Host.RubyHttpHost.Start() in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\Mocks\MockHttpService\Host\RubyHttpHost.cs:line 66
   at PactNet.Mocks.MockHttpService.MockProviderService.Start() in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\Mocks\MockHttpService\MockProviderService.cs:line 137
   at PactNet.PactBuilder.MockService(Int32 port, JsonSerializerSettings jsonSerializerSettings, Boolean enableSsl, IPAddress host, String sslCert, String sslKey) in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\PactBuilder.cs:line 101
   at PactNet.PactBuilder.MockService(Int32 port, Boolean enableSsl, IPAddress host, String sslCert, String sslKey) in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\PactNet\PactBuilder.cs:line 70
   at Consumer.Tests.ConsumerEventApiPact..ctor() in C:\Users\AshleyPoole\Downloads\pact-net-master-3\pact-net-master\Samples\EventApi\Consumer.Tests\ConsumerEventApiPact.cs:line 28
----- Inner Stack Trace -----
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
----- Inner Stack Trace -----
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----

I'm having the same issue as @AshleyPoole. Noticed windows devs were struggling and having replicated his steps with the samples am having the same issue.

@Igor-Pchelko
Copy link

Igor-Pchelko commented Jun 14, 2020

Hello, I'm trying to run consumer on OSX. It has the same issue. Looks like the mock service isn't running.
I've tried to run from /Consumer/tests/bin/Debug/netcoreapp3.1/pact-osx/bin:

 ./pact-mock-service --help start

And it responds with:

/Users/.../Consumer/tests/bin/Debug/netcoreapp3.1/pact-osx/lib/ruby/bin/ruby: line 14: D/pact/pact-workshop-dotnet-core-v1/CompletedSolution/Consumer/tests/bin/Debug/netcoreapp3.1/pact-osx/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory

Here is the tests.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\src\consumer.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
    <PackageReference Include="PactNet.OSX" Version="2.5.4" />
    <PackageReference Include="PactNet.Windows" Version="2.5.4" />
    <PackageReference Include="PactNet.Linux.x86" Version="2.5.4" />
    <PackageReference Include="xunit" Version="2.3.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
  </ItemGroup>

</Project>

I've used the https://github.com/tdshipley/pact-workshop-dotnet-core-v1. Just replaced TargetFramework with netcoreapp3.1 and bumped PactNet nuget version to the latest 2.5.4.

Is it something with standalone ruby binaries?

e.g. pact-foundation/pact-ruby-standalone#37 ?

I've tried to install on OSX latest https://github.com/pact-foundation/pact-ruby-standalone/releases/tag/v1.85.0
So far no luck:

./pact-mock-service --help start

/.../pact/pact/lib/ruby/bin/ruby: line 14: D/pact/pact/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory

Local ruby version is (if it matters):

ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

UPD: Bumping ruby version to the latest 2.7.1p83 has no effect.

UPD: Added corresponding issue for standalone ruby pact: pact-foundation/pact-ruby-standalone#54

UPD: The same issue is applicable for https://github.com/bethesque/pact-net-e2e-example

@KennyDM
Copy link

KennyDM commented Mar 10, 2021

Is there any solution on this issue yet, I am currently experiencing the same.

@KennyDM
Copy link

KennyDM commented Mar 11, 2021

I have been able to go around the issue by manually installing and starting up the pact mock service via https://github.com/pact-foundation/pact-mock_service:

sudo pact-mock-service --consumer "ConsumerName" --provider "ProviderName" --port 9222 --pact-dir "./pacts" --log ./pacts/mock_service.log --pact-specification-version 2

When running the tests, and connecting the MockServer to localhost:9222, I no longer receive the HttpRequestExceptions, and my pacts are being build correctly.

@adamrodger
Copy link
Contributor

Glad you got this sorted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants