pact-mock_server 500 "No interaction found ..."

1,741 views
Skip to first unread message

Michael Hargiss

unread,
Oct 14, 2016, 6:23:04 PM10/14/16
to Pact
I'm using the pact (1.9.4) gem which uses pact-mock_service (0.10.2). I don't understand this 500 error message from the pact-mock_server:

Features API
  GET
D, [2016-10-14T17:24:34.771306 #21948] DEBUG -- : Calling API: FeaturesApi.features_get ...
  Trying ::1...
Connected to localhost (::1) port 1234 (#0)
GET /api/features?quiz_id=1 HTTP/1.1
Host: localhost:1234
User-Agent: Swagger-Codegen/1.0.0/ruby
Content-Type: application/json
Accept: application/json

HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Server: WEBrick/1.3.1 (Ruby/2.3.1/2016-04-26)
Date: Fri, 14 Oct 2016 21:24:34 GMT
Content-Length: 89
Connection: Keep-Alive

Connection #0 to host localhost left intact
D, [2016-10-14T17:24:34.775727 #21948] DEBUG -- : HTTP response body ~BEGIN~
{"message":"No interaction found for GET /api/features?quiz_id=1","interaction_diffs":[]}


My test:

require_relative '../pact_helper'

RSpec.describe 'Features API', pact: true do
  let(:config) do
    config = SwaggerClient::Configuration.new
    config.scheme = 'http'
    config.base_path = '/api'
    config.host = 'localhost:1234'
    config.timeout = 5
    config.debugging = true
    config.verify_ssl = false
    config.verify_ssl_host = false
    config
  end
  let(:client) { SwaggerClient::ApiClient.new(config) }
  subject { SwaggerClient::FeaturesApi.new(client) }

  describe 'GET' do
    let(:opts) { { quiz_id: 1 } }
    let(:setup) do
      quiz_api.given('a quiz with features')
              .upon_receiving('a request for the quiz\'s features')
              .with(method: :get, path: '/features', query: opts)
              .will_respond_with(
                status: 200,
                headers: { 'Content-Type' => 'application/json' }
              )
    end

    # TODO: define spec
    it 'returns the features for the quiz' do
      # features = []
      # expect(subject.features_get(opts)).to eq(features)
      result = subject.features_get(opts)
      p result
    end
  end
end


I've used Pact successfully on other projects.

It seems the POST /interactions is failing. Any ideas or suggestions for debugging?

Matt Fellows

unread,
Oct 14, 2016, 7:05:10 PM10/14/16
to Pact
It looks like your expectation is to receive a GET on '/features' when it should be '/api/features', so pact is complaining that it got a message that wasn't expected.

i.e. I think it should be:

.with(method: :get, path: '/api/features', query: opts)

Michael Hargiss

unread,
Oct 15, 2016, 8:14:37 AM10/15/16
to Pact
Same result  :/

Matt Fellows

unread,
Oct 15, 2016, 8:57:37 AM10/15/16
to Michael Hargiss, Pact

Are you able to post the pact logs or even a runnable gist for us? I think you're right in that perhaps the interactions aren't being registered.


--
You received this message because you are subscribed to the Google Groups "Pact" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pact-support+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Hargiss

unread,
Oct 15, 2016, 10:11:08 AM10/15/16
to Pact, mdha...@gmail.com
pact.log:
I, [2016-10-15T08:12:03.978996 #27363]  INFO -- : Starting app Quiz API #<Pact::MockService::App:0x007f9d76f62aa0> on port 1234...
I, [2016-10-15T08:12:04.094271 #27363]  INFO -- : Started on port 1234
I, [2016-10-15T08:12:04.121629 #27363]  INFO -- : Clearing all expectations
I, [2016-10-15T08:12:04.129746 #27363]  INFO -- : Verifying interactions for Features API GET returns the features for the quiz
D, [2016-10-15T08:12:04.135901 #27363] DEBUG -- : Supposed to be stopping

quiz_api_mock_service.log:
I, [2016-10-15T08:12:04.124551 #27363]  INFO -- : Cleared interactions before example "Features API GET returns the features for the quiz"
I, [2016-10-15T08:12:04.128838 #27363]  INFO -- : Received request GET /api/features?quiz_id=1
D, [2016-10-15T08:12:04.128954 #27363] DEBUG -- : {
  "path": "/api/features",
  "query": "quiz_id=1",
  "method": "get",
  "headers": {
    "Content-Type": "application/json",
    "Host": "localhost:1234",
    "User-Agent": "Swagger-Codegen/1.0.0/ruby",
    "Accept": "application/json",
    "Version": "HTTP/1.1"
  }
}
E, [2016-10-15T08:12:04.128995 #27363] ERROR -- : No matching interaction found for GET /api/features?quiz_id=1
E, [2016-10-15T08:12:04.129007 #27363] ERROR -- : Interaction diffs for that route:
E, [2016-10-15T08:12:04.129016 #27363] ERROR -- : 
W, [2016-10-15T08:12:04.132299 #27363]  WARN -- : Verifying - actual interactions do not match expected interactions for example "Features API GET returns the features for the quiz". 
Unexpected requests:
GET /api/features?quiz_id=1


W, [2016-10-15T08:12:04.132323 #27363]  WARN -- : Unexpected requests:
GET /api/features?quiz_id=1


I, [2016-10-15T08:12:04.135378 #27363]  INFO -- : Writing pact with details {:consumer=>{:name=>"Swagger Client - Ruby"}, :provider=>{:name=>"Quiz API"}, :pactfile_write_mode=>"overwrite", :pact_dir=>"pacts/"}


I'll put together a gist. Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to pact-support...@googlegroups.com.

Matt Fellows

unread,
Oct 16, 2016, 7:54:11 AM10/16/16
to Michael Hargiss, Pact
Yeah, something is not configured correctly (possibly pact_helper.rb). You should see a line somewhere to the following effect:

"Registered expected interaction GET /api/features?quiz_id=1"

To unsubscribe from this group and stop receiving emails from it, send an email to pact-support+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Michael Hargiss

unread,
Oct 17, 2016, 6:43:08 AM10/17/16
to Matt Fellows, Pact
You're both right and Beth nailed it. I forgot the bang. Tunnel vision
is real, folks. :)

Thank you so much!

> Yeah, something is not configured correctly (possibly pact_helper.rb). You should see a line somewhere to the following effect: "Registered expected interaction GET /api/features?quiz_id=1" To unsubscribe from this group and stop receiving emails from it, send an email to pact-support...@googlegroups.com.

Michael Hargiss

unread,
Oct 17, 2016, 6:44:47 AM10/17/16
to Pact, mdha...@gmail.com
You're both right and Beth nailed it. The setup code wasn't getting called. I forgot the bang:

let!(:setup)

Tunnel vision is real, folks.  :)

Thank you so much!

Matt Fellows

unread,
Oct 17, 2016, 7:42:05 AM10/17/16
to Pact, mdha...@gmail.com
Great to hear! :)
Reply all
Reply to author
Forward
0 new messages