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

Unable to run real device- Pactconsumer #129

Open
vivekthambikannu opened this issue May 28, 2022 · 4 comments
Open

Unable to run real device- Pactconsumer #129

vivekthambikannu opened this issue May 28, 2022 · 4 comments

Comments

@vivekthambikannu
Copy link

Hi, I am using pact consumer in my project, real time device only able to run my project unable to run in simulator.
my local ip address is = 120.138.12.180, iam getting this error
failed - Error setting up pact: The request timed out.
failed - Verification error (check build log for mismatches): The request timed out.
My code
let verificationService = PactVerificationService(url: "http://120.138.12.180/", port: 1234)
mockService = MockService(provider: "Provider", consumer: "iOS", pactVerificationService: verificationService)

@surpher
Copy link
Contributor

surpher commented May 29, 2022

Is your Pact mock service running on 120.138.12.180:1234?

@andrewspinks
Copy link
Collaborator

Can you access any other things on the computer from the device? You can check for any network issues by running a simple http server on port 1234 on your computer, and trying to access that from device's browser. If that doesn't work, there is some sort of network issue between the device and computer which you will need to resolve.

@vivekthambikannu
Copy link
Author

vivekthambikannu commented May 30, 2022

Is your Pact mock service running on 120.138.12.180:1234?

yes my mock service running on this url : http://120.138.12.180:1234
This my code
let verificationService = PactVerificationService(url: "http://120.138.12.180", port: 1234)
mockService = MockService(provider: "SomeName Provider", consumer: "SomeName iOS", pactVerificationService: verificationService)

func testConsumerMaintenance() {
    let apiService = ApiService()
    let urL = mockService.baseUrl
    print("localUrl",urL)
    guard let url = URL(string: "\(urL)/banner") else {
        XCTFail("Failed to prepare url!")
        return
    }
    mockService.given("an alligator exists")
                      .uponReceiving("a request for all alligators")
                      .withRequest(method:.GET, path: "/banner",headers: ["Authorization": "Bearer a.b.c"])
                      .willRespondWith(status: 200,
                                       body: userResponse)

    //Run the tests
    mockService.run(timeout: 10000) { (testComplete) -> Void in
        apiService.apiPostMethod(url: url, withHttpMethod: .GET) { (alligators) in
            XCTAssertNotNil(alligators)
            XCTAssertEqual(2, alligators?.data?[0].id)
          testComplete()
        }
      }
    }

@surpher
Copy link
Contributor

surpher commented May 31, 2022

The failure

failed - Error setting up pact: The request timed out.
failed - Verification error (check build log for mismatches): The request timed out.

means that your API client did not trigger or the requests did not reach Pact Mock Service.
Does you apiService handle and/or display HTTP errors?

That is assuming you're using pact-ruby-standalone, but even then, if you're using it like a standalone mock provider, it would most likely give you invalid Pact contract file as one pact-ruby-standalone mock service instance should be used for only one test run. Otherwise you end up stacking up all the Pact unit tests you run for the life of the mock service.

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