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

Karate mock server slow to start up under certain circumstances #1409

Closed
theathlete3141 opened this issue Dec 21, 2020 · 1 comment
Closed
Assignees

Comments

@theathlete3141
Copy link

theathlete3141 commented Dec 21, 2020

Following on from #1395, I found that the presence of "Background" in a mock server feature file appears to affect the start up speed of a mock server

Using the HEAD of the develop branch (after #1395 had been resolved, PR #1408), I have the attached example files which should be added to karate-gatling/src/test/scala.
example.zip

When running a basic Karate-Gatling simulation

class KarateSimulation extends Simulation {

  val mock = Properties.propOrEmpty("mock")
  val feature = "classpath:example/mockServer" + mock + ".feature"
  val server = MockServer.feature(feature).build()
  val serverUrl = "http://localhost:" + server.getPort
  System.setProperty("server.url", serverUrl)

  val example = scenario("example")
    .exec(karateFeature("classpath:example/example.feature"))

  setUp(
    example.inject(rampUsers(100) during (10 seconds))
  )
}

With example.feature

Feature:

  Scenario:
    * url karate.properties['server.url']
    * path ''
    * method get
    * status 200
    * match response == { success: true }

Against the mock server mockServer1.feature:

Feature:

  Scenario: pathMatches('')
    * def response = { success: true }

And ran using:

mvn test -D gatling.simulationClass=example.KarateSimulation -D mock=1

Then there is a small (~1s) gap between the first users and first requests.
Screenshot 2020-12-21 at 13 10 43

For comparison, a pure Gatling simulation doesn't do this:

class GatlingSimulation extends Simulation {

  val mock = Properties.propOrEmpty("mock")
  val feature = "classpath:example/mockServer" + mock + ".feature"
  val server = MockServer.feature(feature).build()
  val serverUrl = "http://localhost:" + server.getPort
  System.setProperty("server.url", serverUrl)
  val protocol = http.baseUrl(serverUrl)

  val example = scenario("example")
    .exec(
      http("GET /")
        .get("/")
        .check(status.is(200))
        .check(jsonPath("$.success").is("true"))
    )

  setUp(
    example.inject(rampUsers(100) during (10 seconds)).protocols(protocol)
  )
}
mvn test -D gatling.simulationClass=example.GatlingSimulation -D mock=1

Screenshot 2020-12-21 at 13 10 54

I found that this can be fixed by adding a non-empty "Background" to the mock server:
mockServer2.feature

Feature:

  Background:
    * print 'Background'

  Scenario: pathMatches('')
    * def response = { success: true }

Ran using:

mvn test -D gatling.simulationClass=example.KarateSimulation -D mock=2

Screenshot 2020-12-21 at 13 12 20

However, an empty "Background" displays the original problem
mockServer3.feature

Feature:

  Background:

  Scenario: pathMatches('')
    * def response = { success: true }

Ran using:

mvn test -D gatling.simulationClass=example.KarateSimulation -D mock=3

Screenshot 2020-12-21 at 13 12 48

@ptrthomas
Copy link
Member

closing as wontfix these are called mocks for a reason

theathlete3141 pushed a commit to theathlete3141/karate that referenced this issue Dec 21, 2020
ptrthomas added a commit that referenced this issue Dec 21, 2020
#1409 - fix Karate mock server slow to start up under certain circumstances
@ptrthomas ptrthomas added this to the 1.0.0 milestone Dec 21, 2020
@ptrthomas ptrthomas removed this from the 1.0.0 milestone Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants