242Studios's avatar

Pest Slow on Sail?

Is anybody else having a problem with their tests running brutally slow on Laravel Sail? I'm also on an M1 mac if that makes any difference. But just a test asserting that true is true, takes 3sec to run. Would appreciate any input.

0 likes
5 replies
LaryAI's avatar
Level 58

There could be several reasons why tests are running slow on Laravel Sail, especially on an M1 Mac. Here are a few potential solutions to try:

  1. Update Docker: Make sure you have the latest version of Docker installed on your machine. You can check for updates and install them from the Docker website.

  2. Increase Docker resources: By default, Docker may not be allocated enough resources, which can slow down test execution. You can try increasing the resources allocated to Docker by going to Docker Desktop > Preferences > Resources and adjusting the CPU and memory settings.

  3. Optimize test configuration: Review your test configuration to ensure it is optimized. For example, if you have unnecessary database migrations or seeders running before each test, it can significantly slow down the test suite. Consider using in-memory databases like SQLite for faster test execution.

  4. Use parallel testing: Laravel supports parallel testing, which can significantly speed up test execution. You can configure the number of parallel processes in your phpunit.xml file. For example, you can set the processes attribute to a higher value like 5 to run tests in parallel.

  5. Optimize your tests: Review your tests to identify any potential bottlenecks or slow-running code. Look for areas where you can optimize queries, reduce database interactions, or use test doubles (mocks or stubs) instead of hitting external services.

If you have tried the above solutions and are still experiencing slow test execution, you can try reaching out to the Laravel Sail community or Laracasts forum for further assistance.

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
         processIsolation="false"
         parallelizeMethods="true"
         parallelizeClasses="true"
         parallelizeSuites="true"
         executionOrder="defects">
    <!-- ... -->
    <php>
        <!-- ... -->
        <env name="DB_CONNECTION" value="sqlite"/>
        <!-- ... -->
    </php>
    <!-- ... -->
</phpunit>

Remember to adjust the configuration according to your specific needs and environment.

242Studios's avatar

Yea, no luck with those. Still runs brutally slow.

242Studios's avatar

So I put the project into Laravel Herd and ran the tests there and they ran significantly faster. It's definitely a problem with running the tests in Sail. When I run them in Sail, they take 124 seconds as opposed to 5 seconds in Herd.

1 like
MrMoto9000's avatar

Switching to straight PHPUnit tests seems to be the answer. 4x/5x quicker on Sail.

Please or to participate in this conversation.