code-distortion / adapt

A Laravel package that builds databases for your tests, improving their speed
MIT License
24 stars 3 forks source link

Delay upon start-up when looking for stale databases to remove #2

Closed code-distortion closed 2 years ago

code-distortion commented 2 years ago

Description:

When Adapt starts, before building databases, it checks for stale databases to remove. It does this by looping through the present connections, and checking the databases within. However these connections can time-out, adding a delay to the test-process.

This is particularly prevalent when using a PostgreSQL database, because the way Laravel's config is set up means that the (unused) MySQL connection exists, but with the PostgreSQL server's details. Adapt then tries to connect to the PostgreSQL server with the MyQSL client, and this particular combination takes 1 minute before timing out.

Logs:

[2022-06-21 14:22:12] testing.DEBUG: ADAPT: Looking for stale things to remove  
[2022-06-21 14:22:12] testing.DEBUG: ADAPT: Generated a content-based build-source checksum (0ms)  
[2022-06-21 14:22:12] testing.DEBUG: ADAPT: Retrieved database list (connection: "sqlite", driver: "sqlite") (0ms)  
[2022-06-21 14:22:12] testing.DEBUG: ADAPT: - No databases were found (0ms)  
[2022-06-21 14:23:12] testing.WARNING: ADAPT: Could not retrieve database list (connection: "mysql", driver: "mysql") (1m)  
[2022-06-21 14:23:12] testing.DEBUG: ADAPT: Retrieved database list (connection: "pgsql", driver: "pgsql") (13ms)  
[2022-06-21 14:23:12] testing.DEBUG: ADAPT: - Found database "db_484a0c_399f58dcb9c0" (usable) (7ms)  
[2022-06-21 14:23:12] testing.WARNING: ADAPT: Could not retrieve database list (connection: "sqlsrv", driver: "sqlsrv") (1ms)  
[2022-06-21 14:23:12] testing.DEBUG: ADAPT: Retrieved snapshot list (0ms)  
[2022-06-21 14:23:12] testing.DEBUG: ADAPT: - Found snapshot "/var/www/html/database/adapt-test-storage/snapshots/snapshot.db.484a0c-33d736a4f21d.pgsql" (usable) (0ms)  
[2022-06-21 14:23:12] testing.DEBUG: ADAPT: - Found snapshot "/var/www/html/database/adapt-test-storage/snapshots/snapshot.db.484a0c-a858496f4d3b.pgsql" (usable) (0ms)  
[2022-06-21 14:23:12] testing.DEBUG: ADAPT: Nothing found to remove - total time taken (1m)

…
code-distortion commented 2 years ago

I have addressed this problem by getting Adapt to only look for stale databases via connections that are being prepared.

This way, if you only use the pgsql connection for example, it won't search using the mysql connection.