Skip to content

Conversation

@slt
Copy link
Contributor

@slt slt commented Jun 12, 2023

Pact consumer tests are supposed to be like unit tests but mine were taking 2 seconds+ each, the majority of which was php sleep()

  • Allow SetHealthCheckRetrySec / PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC
    to be a float so it can be set to 0.1 instead of 1.

  • Use usleep instead of sleep so that the retry seconds can be a < 1 second.

  • Increase the total number of attempts so it still tries for ~10 seconds.

  • Remove sleeps in PactMessage which do not appear to be needed.

Results in my environment

3 pact consumer tests
Before - 00:06.577s
After - 00:01.603s

32 pact message tests
Before - 00:55.202s
After - 00:21.900s

slt added 2 commits June 12, 2023 00:59
* Fix config setters returning a interface which prevents
  chaining when static analysis tools are in use as the
  interfaces are only a subset of what the class can do.

* Set defaults similar to MockServerEnvConfig for
  timeouts as these are typed but not set to a value
  by default, forcing you to set them to avoid an error.
Pact consumer tests are supposed to be like unit tests
but mine were taking 2 seconds+ each, the majority of which was a
php sleep()

Lots of unnecessary sleeps were slowing down my api and message tests.

* Allow SetHealthCheckRetrySec / PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC
  to be a float so it can be set to 0.1 instead of 1.

* Use usleep instead of sleep so that the retry seconds can be a < 1 second.

* Increase the total number of attempts so it still tries for ~10 seconds.

* Remove sleeps when PactMessage which do not appear to be needed.
@slt slt changed the title Fast Gotta go fast Jun 12, 2023
@mefellows
Copy link
Member

This is great, thanks for all of these PR's @slt. I'm not qualified to review the PHP bits, so will wait for a maintainer - but just wanted to pass on my gratitude.

@YOU54F YOU54F mentioned this pull request Jul 12, 2023
Copy link
Member

@YOU54F YOU54F left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the linter is failing, I've noted a comment

return $service->healthCheck();
} catch (ConnectionException $e) {
\sleep($retrySec);
\usleep(round($retrySec * 1000000));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

round returns a float and usleep expects an int

https://www.php.net/manual/en/function.round.php
https://www.php.net/manual/en/function.usleep.php

usleep(intval(round($retrySec * 1000000)));

@YOU54F
Copy link
Member

YOU54F commented Jul 14, 2023

@YOU54F
Copy link
Member

YOU54F commented Jul 14, 2023

complete in #322

@YOU54F YOU54F closed this Jul 14, 2023
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

Successfully merging this pull request may close these issues.

3 participants