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

Pact-mock-server/Webrick server returns ECONNRESET #34

Open
ichyr opened this issue Dec 1, 2015 · 6 comments
Open

Pact-mock-server/Webrick server returns ECONNRESET #34

ichyr opened this issue Dec 1, 2015 · 6 comments

Comments

@ichyr
Copy link

ichyr commented Dec 1, 2015

Hi!
I have 2 unit test written in js using ( pact-consumer-js-dsl ) that create interactions like in the README for that library e.g. alligators/Mary, alligators/Pete They are separated in two different files. In each file I set up the same logic:

describe("Client", function() {
  var client, helloProvider;

  beforeEach(function() {
    //ProviderClient is the class you have written to make the HTTP calls to the provider
    client = new ProviderClient('http://localhost:1234');
    helloProvider = Pact.mockService({
      consumer: 'Hello Consumer',
      provider: 'Hello Provider',
      port: 1234,
      done: function (error) {
        expect(error).toBe(null);
      }
    });
  });

  it("should say hello", function(done) {
    helloProvider
      .given("an alligator with the name Mary exists")
      .uponReceiving("a request for an alligator")
      .withRequest("get", "/alligators/Mary", {
        "Accept": "application/json"
      }).willRespondWith(200, {
        "Content-Type": "application/json"
      }, {
        "name": "Mary"
      });

    helloProvider.run(done, function(runComplete) {
      expect(client.getAlligatorByName("Mary")).toEqual(new Alligator("Mary"));
      runComplete();
    });
  });
});

When I trigger them the pact json files are generated. But after they are generated the pact-mock-server writes in logs that:

ERROR Errno:ECONNRESET: An existing connection was forcibly closed by the remote host. @ io-Fillbuf - fd:5

I don't know if this is the correct way of behavior so want to know if those errors that I get are
image`

After this error occurs, the server ( started on localhost:1234 ) as response to request localhost:1234/alligators/Mary (specified in the js code above) will response with:

image

Is this a BUG in pact-mock-server and how this can by solved?

P.S. These are errors of WebRick server, so in the internet people say that switching to thin server resolves this.

@ichyr
Copy link
Author

ichyr commented Dec 1, 2015

Investigation.

Here are 3 Use cases described:

  1. USE CASE Duplicate interaction check needs to occur when the interaction is set up, not on replay #1 ( 2 files. different consumer but same provider )
  2. USE CASE Making CORS work #2 ( 2 files. same consumer and provider )
  3. USE CASE # 3 ( files merged into 1 files. same consumer and provider)

I set a standalone pact server running with the following command:

pact-mock-service.bat --port 1234 --pact-specification-version 2.0.0 --pact-dir ../../pacts

I have 2 clients with different endpoints and consumer names:

**Mary.js**
    'use strict';

    describe('Client', function() {
        var client, helloProvider, http;

        beforeEach(inject(function() {
            //ProviderClient is the class you have written to make the HTTP calls to the provider
            var i = angular.injector(['ng']), rs = i.get('$rootScope');
            http = i.get('$http');
            var ProviderClient = function(hostName) {
                return {
                    get: function(url) {
                        console.log('GET METHOD CALLED');
                        return http.get('http://localhost:1234/alligators/Mary');
                    }
                }
            };

            client = new ProviderClient('http://localhost:1234');
            helloProvider = Pact.mockService({
                consumer: 'Peter1',
                provider: 'Data1',
                port: 1234,
                done: function(error) {
                    expect(error).toBe(null);
                }
            });
        }));

        it('should say hello', function() {
            helloProvider
                .given('an alligator with the name Mary exists')
                .uponReceiving('a request for an alligator')
                .withRequest('get', '/alligators/Mary', {
                }).willRespondWith(200, {
                'Content-Type': 'application/json'
            }, {
                'name': 'Mary'
            });
            var flag;
            var done = function() {
                console.log("It's DONE");
            };
            var result;
            runs(function() {
                helloProvider.run(done, function(runComplete) {
                    client.get('/alligators/Mary').then(function(data) {
                        console.log('CALLLBACK CALLED');
                        result = data.data;
                        flag = true;
                        runComplete();
                    }, function(error) {
                        console.log(error);
                        flag = true;
                        runComplete();
                    });

                })
            });
            waitsFor(function() {
                return flag;
            });

            runs(function() {
                expect(result).toEqual({name: 'Mary'});
            });
        });
    });
**Tommy.js**
    'use strict';

    describe('Client', function() {
        var client, helloProvider, http;

        beforeEach(inject(function() {
            //ProviderClient is the class you have written to make the HTTP calls to the provider
            var i = angular.injector(['ng']), rs = i.get('$rootScope');
            http = i.get('$http');
            var ProviderClient = function(hostName) {
                return {
                    get: function(url) {
                        console.log('GET METHOD CALLED');
                        return http.get('http://localhost:1234/alligators/Tommy');
                    }
                }
            };

            client = new ProviderClient('http://localhost:1234');
            helloProvider = Pact.mockService({
                consumer: 'Antuanett1',
                provider: 'Data1',
                port: 1234,
                done: function(error) {
                    expect(error).toBe(null);
                }
            });
        }));

        it('should say hello', function() {
            helloProvider
                .given('an alligator with the name Tommy exists')
                .uponReceiving('a request for an alligator')
                .withRequest('get', '/alligators/Tommy', {
                }).willRespondWith(200, {
                    'Content-Type': 'application/json'
                }, {
                    'name': 'Tommy'
                });
            var flag;
            var done = function() {
                console.log("It's DONE");
            };
            var result;
            runs(function() {
                helloProvider.run(done, function(runComplete) {
                    client.get('/alligators/Tommy').then(function(data) {
                        console.log('CALLLBACK CALLED');
                        result = data.data;
                        flag = true;
                        runComplete();
                    }, function(error) {
                        console.log(error);
                        flag = true;
                        runComplete();
                    });

                })
            });
            waitsFor(function() {
                return flag;
            });

            runs(function() {
                expect(result).toEqual({name: 'Tommy'});
            });
        });
    });

USE CASE #1 ( different consumer but same provider )

After starting server and running the tests I get the following result:

[2015-12-01 12:12:53] INFO  WEBrick 1.3.1
[2015-12-01 12:12:53] INFO  ruby 2.1.5 (2014-11-13) [i386-mingw32]
[2015-12-01 12:12:53] INFO  WEBrick::HTTPServer#start: pid=9660 port=1234
I, [2015-12-01T12:13:25.352204 #9660]  INFO -- : Registered expected interaction GET /alligators/Tommy
D, [2015-12-01T12:13:25.354157 #9660] DEBUG -- : {
  "description": "a request for an alligator",
  "provider_state": "an alligator with the name Tommy exists",
  "request": {
    "method": "get",
    "path": "/alligators/Tommy",
    "headers": {
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "name": "Tommy"
    }
  }
}
I, [2015-12-01T12:13:25.396151 #9660]  INFO -- : Received request GET /alligators/Tommy
D, [2015-12-01T12:13:25.397127 #9660] DEBUG -- : {
  "path": "/alligators/Tommy",
  "query": "",
  "method": "get",
  "headers": {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34",
    "Accept": "application/json, text/plain, */*",
    "Referer": "http://localhost:8080/context.html",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2015-12-01T12:13:25.407870 #9660]  INFO -- : Found matching response for GET /alligators/Tommy
D, [2015-12-01T12:13:25.408846 #9660] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Tommy"
  }
}
I, [2015-12-01T12:13:25.431308 #9660]  INFO -- : Verifying - interactions matched for example ""
I, [2015-12-01T12:13:25.444981 #9660]  INFO -- : Registered expected interaction GET /alligators/Mary
D, [2015-12-01T12:13:25.445957 #9660] DEBUG -- : {
  "description": "a request for an alligator",
  "provider_state": "an alligator with the name Mary exists",
  "request": {
    "method": "get",
    "path": "/alligators/Mary",
    "headers": {
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "name": "Mary"
    }
  }
}
I, [2015-12-01T12:13:25.460606 #9660]  INFO -- : Writing pact with details {:consumer=>{:name=>"Antuanett1"}, :provider=>{:name=>"Data1"}}
I, [2015-12-01T12:13:25.462559 #9660]  INFO -- : Writing pact for Data1 to ../../pacts/antuanett1-data1.json
I, [2015-12-01T12:13:25.470372 #9660]  INFO -- : Received request GET /alligators/Mary
D, [2015-12-01T12:13:25.471349 #9660] DEBUG -- : {
  "path": "/alligators/Mary",
  "query": "",
  "method": "get",
  "headers": {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34",
    "Accept": "application/json, text/plain, */*",
    "Referer": "http://localhost:8080/context.html",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2015-12-01T12:13:25.480138 #9660]  INFO -- : Found matching response for GET /alligators/Mary
D, [2015-12-01T12:13:25.481115 #9660] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Mary"
  }
}
I, [2015-12-01T12:13:25.502600 #9660]  INFO -- : Verifying - interactions matched for example ""
I, [2015-12-01T12:13:25.527992 #9660]  INFO -- : Writing pact with details {:consumer=>{:name=>"Peter1"}, :provider=>{:name=>"Data1"}}
I, [2015-12-01T12:13:25.528968 #9660]  INFO -- : Writing pact for Data1 to ../../pacts/peter1-data1.json
[2015-12-01 12:13:26] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:7
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
[2015-12-01 12:13:26] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:5
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
[2015-12-01 12:13:26] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:6
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'

Until here everything is great:
1. I get pact file generated
2. Test inside those files ( mary, tommy ) pass

But when I want to query mock service with requests that were supposed to exist on server, as we generated pact files,
I get the following results:

  1. http://localhost:1234/alligators/Mary
        {
          "name": "Mary"
        }
  1. http://localhost:1234/alligators/Tommy
        {
          "message": "No interaction found for GET /alligators/Tommy",
          "interaction_diffs": []
        }

Does pact-mock-server supposed to work this way?

I thought it is forming in-memory collection of interaction, so I can query each set up interaction.

USE CASE #2 ( same consumer and provider )

Both files have consumer: 'Peter1'.

After running pact-mock-server again and running the test we get the following output:

[2015-12-01 12:23:21] INFO  WEBrick 1.3.1
[2015-12-01 12:23:21] INFO  ruby 2.1.5 (2014-11-13) [i386-mingw32]
[2015-12-01 12:23:21] INFO  WEBrick::HTTPServer#start: pid=9668 port=1234
I, [2015-12-01T12:23:28.638064 #9668]  INFO -- : Registered expected interaction GET /alligators/Tommy
D, [2015-12-01T12:23:28.640017 #9668] DEBUG -- : {
  "description": "a request for an alligator",
  "provider_state": "an alligator with the name Tommy exists",
  "request": {
    "method": "get",
    "path": "/alligators/Tommy",
    "headers": {
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "name": "Tommy"
    }
  }
}
I, [2015-12-01T12:23:28.676152 #9668]  INFO -- : Received request GET /alligators/Tommy
D, [2015-12-01T12:23:28.677128 #9668] DEBUG -- : {
  "path": "/alligators/Tommy",
  "query": "",
  "method": "get",
  "headers": {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34",
    "Accept": "application/json, text/plain, */*",
    "Referer": "http://localhost:8080/context.html",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2015-12-01T12:23:28.686894 #9668]  INFO -- : Found matching response for GET /alligators/Tommy
D, [2015-12-01T12:23:28.687871 #9668] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Tommy"
  }
}
I, [2015-12-01T12:23:28.699590 #9668]  INFO -- : Verifying - interactions matched for example ""
I, [2015-12-01T12:23:28.731818 #9668]  INFO -- : Registered expected interaction GET /alligators/Mary
D, [2015-12-01T12:23:28.733771 #9668] DEBUG -- : {
  "description": "a request for an alligator",
  "provider_state": "an alligator with the name Mary exists",
  "request": {
    "method": "get",
    "path": "/alligators/Mary",
    "headers": {
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "name": "Mary"
    }
  }
}
I, [2015-12-01T12:23:28.744514 #9668]  INFO -- : Writing pact with details {:consumer=>{:name=>"Peter1"}, :provider=>{:name=>"Data1"}}
I, [2015-12-01T12:23:28.745490 #9668]  INFO -- : Writing pact for Data1 to ../../pacts/peter1-data1.json
I, [2015-12-01T12:23:28.757209 #9668]  INFO -- : Received request GET /alligators/Mary
D, [2015-12-01T12:23:28.758186 #9668] DEBUG -- : {
  "path": "/alligators/Mary",
  "query": "",
  "method": "get",
  "headers": {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34",
    "Accept": "application/json, text/plain, */*",
    "Referer": "http://localhost:8080/context.html",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2015-12-01T12:23:28.766975 #9668]  INFO -- : Found matching response for GET /alligators/Mary
D, [2015-12-01T12:23:28.766975 #9668] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Mary"
  }
}
I, [2015-12-01T12:23:28.780648 #9668]  INFO -- : Verifying - interactions matched for example ""
I, [2015-12-01T12:23:28.799203 #9668]  INFO -- : Writing pact with details {:consumer=>{:name=>"Peter1"}, :provider=>{:name=>"Data1"}}
I, [2015-12-01T12:23:28.800180 #9668]  INFO -- : Writing pact for Data1 to ../../pacts/peter1-data1.json
[2015-12-01 12:23:29] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:6
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
[2015-12-01 12:23:29] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:5
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
[2015-12-01 12:23:29] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:7
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread' 

Queries to localhost:1234 result in the same as in use case # 1.

USE CASE # 3 (files merged into 1 files)

I've copied the expectation from Tommy.js in the end of Mary.js. Thus no dublication of setting up the Pact.mockservice occurs.
Now we have the following scenario

**Mary.js**
    'use strict';

    describe('Client', function() {
        var client, helloProvider, http;

        beforeEach(inject(function() {
            //ProviderClient is the class you have written to make the HTTP calls to the provider
            var i = angular.injector(['ng']), rs = i.get('$rootScope');
            http = i.get('$http');
            var ProviderClient = function(hostName) {
                return {
                    get: function(url) {
                        console.log('GET METHOD CALLED');
                        return http.get('http://localhost:1234/' + url);
                    }
                }
            };

            client = new ProviderClient('http://localhost:1234');
            helloProvider = Pact.mockService({
                consumer: 'Peter1',
                provider: 'Data1',
                port: 1234,
                done: function(error) {
                    expect(error).toBe(null);
                }
            });
        }));

        it('should say hello Mary', function() {
            helloProvider
                .given('an alligator with the name Mary exists')
                .uponReceiving('a request for an alligator')
                .withRequest('get', '/alligators/Mary', {
                }).willRespondWith(200, {
                'Content-Type': 'application/json'
            }, {
                'name': 'Mary'
            });
            var flag;
            var done = function() {
                console.log("It's DONE");
            };
            var result;
            runs(function() {
                helloProvider.run(done, function(runComplete) {
                    client.get('/alligators/Mary').then(function(data) {
                        console.log('CALLLBACK CALLED');
                        result = data.data;
                        flag = true;
                        runComplete();
                    }, function(error) {
                        console.log(error);
                        flag = true;
                        runComplete();
                    });

                })
            });
            waitsFor(function() {
                return flag;
            });

            runs(function() {
                expect(result).toEqual({name: 'Mary'});
            });
        });

        it('should say hello Tommy', function() {
            helloProvider
                .given('an alligator with the name Tommy exists')
                .uponReceiving('a request for an alligator')
                .withRequest('get', '/alligators/Tommy', {
                }).willRespondWith(200, {
                    'Content-Type': 'application/json'
                }, {
                    'name': 'Tommy'
                });
            var flag;
            var done = function() {
                console.log("It's DONE");
            };
            var result;
            runs(function() {
                helloProvider.run(done, function(runComplete) {
                    client.get('/alligators/Tommy').then(function(data) {
                        console.log('CALLLBACK CALLED');
                        result = data.data;
                        flag = true;
                        runComplete();
                    }, function(error) {
                        console.log(error);
                        flag = true;
                        runComplete();
                    });

                })
            });
            waitsFor(function() {
                return flag;
            });

            runs(function() {
                expect(result).toEqual({name: 'Tommy'});
            });
        });
    });

Running this code also generated the same results. Console output:

[2015-12-01 12:30:59] INFO  WEBrick 1.3.1
[2015-12-01 12:30:59] INFO  ruby 2.1.5 (2014-11-13) [i386-mingw32]
[2015-12-01 12:30:59] INFO  WEBrick::HTTPServer#start: pid=7872 port=1234
I, [2015-12-01T12:31:07.297278 #7872]  INFO -- : Registered expected interaction GET /alligators/Mary
D, [2015-12-01T12:31:07.298254 #7872] DEBUG -- : {
  "description": "a request for an alligator",
  "provider_state": "an alligator with the name Mary exists",
  "request": {
    "method": "get",
    "path": "/alligators/Mary",
    "headers": {
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "name": "Mary"
    }
  }
}
I, [2015-12-01T12:31:07.323646 #7872]  INFO -- : Received request GET /alligators/Mary
D, [2015-12-01T12:31:07.325599 #7872] DEBUG -- : {
  "path": "/alligators/Mary",
  "query": "",
  "method": "get",
  "headers": {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34",
    "Accept": "application/json, text/plain, */*",
    "Referer": "http://localhost:8080/context.html",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2015-12-01T12:31:07.335365 #7872]  INFO -- : Found matching response for GET /alligators/Mary
D, [2015-12-01T12:31:07.336342 #7872] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Mary"
  }
}
I, [2015-12-01T12:31:07.353920 #7872]  INFO -- : Registered expected interaction GET /alligators/Tommy
D, [2015-12-01T12:31:07.354897 #7872] DEBUG -- : {
  "description": "a request for an alligator",
  "provider_state": "an alligator with the name Tommy exists",
  "request": {
    "method": "get",
    "path": "/alligators/Tommy",
    "headers": {
    }
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "name": "Tommy"
    }
  }
}
W, [2015-12-01T12:31:07.367593 #7872]  WARN -- : Verifying - actual interactions do not match expected interactions for example "".
Missing requests:
        GET /alligators/Tommy


W, [2015-12-01T12:31:07.371499 #7872]  WARN -- : Missing requests:
        GET /alligators/Tommy


I, [2015-12-01T12:31:07.388101 #7872]  INFO -- : Received request GET /alligators/Tommy
D, [2015-12-01T12:31:07.389078 #7872] DEBUG -- : {
  "path": "/alligators/Tommy",
  "query": "",
  "method": "get",
  "headers": {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34",
    "Accept": "application/json, text/plain, */*",
    "Referer": "http://localhost:8080/context.html",
    "Connection": "Keep-Alive",
    "Accept-Encoding": "gzip",
    "Accept-Language": "en-US,*",
    "Host": "localhost:1234",
    "Version": "HTTP/1.1"
  }
}
I, [2015-12-01T12:31:07.396891 #7872]  INFO -- : Found matching response for GET /alligators/Tommy
D, [2015-12-01T12:31:07.397867 #7872] DEBUG -- : {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Tommy"
  }
}
I, [2015-12-01T12:31:07.409587 #7872]  INFO -- : Verifying - interactions matched for example ""
I, [2015-12-01T12:31:07.434978 #7872]  INFO -- : Writing pact with details {:consumer=>{:name=>"Peter1"}, :provider=>{:name=>"Data1"}}
I, [2015-12-01T12:31:07.435955 #7872]  INFO -- : Writing pact for Data1 to ../../pacts/peter1-data1.json
[2015-12-01 12:31:08] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:7
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
[2015-12-01 12:31:08] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:6
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'
[2015-12-01 12:31:08] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:5
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run'
        C:/Users/tester/train/application/pact/lib/vendor/ruby/2.1.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'

Now the request to alligators/Tommy returns expected response and alligators/Mary fails. I assume this is due to the ordering, as Tommy expectation was set after the Mary.

@bethesque
Copy link
Member

Ok, before I spend half an hour going through all those logs, let me address "I have 2 clients with different endpoints and consumer names:". You can't use the same mock service for both of these, you need two separate mock service instances, each running on a different port. Can you make a repository with the code required to replicate the bug?

@ichyr
Copy link
Author

ichyr commented Dec 2, 2015

@bethesque I've created the sample project.

https://github.com/ichyr/pact-js-example

All relevant set up information is in README.

  • Consumer and provider may be the same in both test. But the result doesn't change.

@mefellows
Copy link
Member

@ichyr Just for reference, in the coming weeks the pact-consumer-dsl will automatically run a mock service transparently to you for this use case. Additionally, we have just added the capability to reset a session between tests that could simplify your code to date.

@bethesque
Copy link
Member

Hi @ichyr, I'm currently on maternity leave with 3 month old twins, so I don't have time to look into this at the moment. @sergei-matheson is maintaining the library while I'm on mat leave.

@bethesque
Copy link
Member

Oh... just realised this is from last year... ignore previous comment. It seems I never followed up - I apologise. I was 8 months pregnant with twins at the time and trying to hand over a project, so it must have gotten lost in the interminable list of things that had to be done that month.

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

3 participants