DiUS / pact-consumer-swift

A Swift / ObjeciveC DSL for creating pacts.
MIT License
98 stars 43 forks source link

Unable to run real device- Pactconsumer #129

Open vivekthambikannu opened 2 years ago

vivekthambikannu commented 2 years ago

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 commented 2 years ago

Is your Pact mock service running on 120.138.12.180:1234?

andrewspinks commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.