pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
72 stars 68 forks source link

Certain input causes mock service to hang #7

Open redbeard opened 9 years ago

redbeard commented 9 years ago

I'll investigate this further later, reporting so not to lose track of this bug.

When setting an expected interaction response with the following body payload, and posting to PACT, the server hangs until HTTP timeout.

Removing the regular expressions from the payload avoids the problem.

{
  "title":"Application Form",
  "questions":[
    {
      "label":"What is your name?",
      "fields":[
        {
          "type":"text",
          "placeholder":"Given name",
          "identifier":"given-name"
        },
        {
          "type":"text",
          "placeholder":"Family name",
          "identifier":"last-name"
        }
      ]
    },
    {
      "label":"What is your address?",
      "fields":[
        {
          "type":"address",
          "identifier":"address"
        }
      ]
    },
    {
      "label":"What is your tax file number?",
      "fields":[
        {
          "type":"text",
          "identifier":"tfn",
          "placeholder":"TFN",
          "validations":[
            {
              "type":"regexp",
              "expression":"([\\d]{3}[^\\d]*){3}",
              "message":"TFN requires 9 digits."
            }
          ],
          "processings":[
            {
              "type":"regexpReplace",
              "expression":"[^\\d]",
              "replace":""
            }
          ]
        }
      ]
    },
    {
      "label":"Employment history:",
      "fields":[
        {
          "type":"text",
          "placeholder":"Employer name",
          "identifier":"employer-name"
        },
        {
          "type":"city",
          "placeholder":"Employer city",
          "identifier":"employer-city"
        }
      ],
      "questions":[
        {
          "repeatable":{
            "min":1
          },
          "label":"Role in the company:",
          "fields":[
            {
              "type":"date",
              "placeholder":"Started",
              "identifier":"start-date"
            },
            {
              "type":"date",
              "placeholder":"Ended",
              "identifier":"end-date"
            },
            {
              "type":"text",
              "placeholder":"Title",
              "identifier":"role-title"
            },
            {
              "type":"text-area",
              "placeholder":"Description",
              "identifier":"role-desc"
            }
          ]
        }
      ]
    }
  ]
}
bethesque commented 9 years ago

Bizarre, haven't had that before. One thing to look at is that it uses JSON.load(because sometimes there are embedded Ruby classes eg. Pact::Term) not JSON.parse.

bethesque commented 9 years ago

Any news on this one?

jbarton123 commented 3 years ago

Hi @bethesque - reviving an old thread here. I've noticed that this is still happening when using matchers that generate a regex pattern. I've been using the PHP Pact library and using matchers such as uuid() or dateTimeISO8601() seem to cause the service to hang.

I noticed when trying to send a curl request once it has hanged, I receive a connection refused so it is like the service has entered an unhealthy state.

What is really interesting is that this has only happened since I have hit a larger number of pacts (I have ~26 pacts to verify against now). When I remove any one of these, it seems to run ok again.

However, when I have replaced these regex matchers with the like() matcher (which I believe just checks for a matching type) this resolves the issue, the service doesn't hang and successfully verifies against all 26 pacts.

bethesque commented 3 years ago

The uuid and dateTimeISO8601 aren't natively supported, so they must be wrappers for "terms" provided by the pact php library. Can you see if you can recreate it using https://github.com/pact-foundation/pact-ruby-standalone-e2e-example ?