Closed mpscholten closed 8 years ago
When running multiple tests in parallel I would recommend to have different sqlite files per run. Is that an option?
Not really, I guess. By using multiple sqlite files per run we'd loose the advantages of phpunit-clever-and-smart.
Some more context: The issue happens when running the tests inside a docker container. Let's say we have a docker container running the phpunit test suite (with a pseudo tty attached, so that you can see the output from phpunit). When you now press CTRL+C, docker will detach the tty from the container but the tests will keep running in the background. If you now change some code and then re-run the tests in another docker container (while the other container has still not finished running the tests) you might get the error from above. It's not happening very often, but when it happens it's very annoying.
@mpscholten did you consider using a different Storage
in your setup?
maybe you could also use a different locking-mode
[1]? I dont have much experience with SQLite so this might not be a viable option after all
Good idea, haven't thought about that yet.
I guess setting the locking-mode
to PENDING
(A PENDING lock means that the process holding the lock wants to write to the database as soon as possible and is just waiting on all current SHARED locks to clear so that it can get an EXCLUSIVE lock. No new SHARED locks are permitted against the database if a PENDING lock is active, though existing SHARED locks are allowed to continue.) should do the job. If I understood this right, the pending lock waits until the database is unlocked and then applies an exclusive lock.
This looks like a great solution. So, should we change the default lock to PENDING
? This should not change behavior for single-test-run environments, but will fix this issue for multi-test-run environments. If everyone is happy with this I'd prepare a pull request :)
I don't know enough about SQLite to judge but if that helps I am certainly fine with it.
Just tested it. PENDING
doesn't work with EXCLUSIVE
. But I just found the real issue :) As long as the Sqlite3Storage
object is living the database is locked (see https://github.com/lstrojny/phpunit-clever-and-smart/blob/master/src/PHPUnit/Runner/CleverAndSmart/Storage/Sqlite3Storage.php#L35). So the second process cannot read/write from/to the database while the first process is still running. But sqlite is automatically getting a lock when firing a query. So we can safely remove line 35 in Sqlite3Storage
and then the second process can access the database as long as the first process is not writing to it at the moment.
Just removed the line in my local copy and tried it out. Seems to be working.
@lstrojny we can close this as https://github.com/lstrojny/phpunit-clever-and-smart/pull/37 was merged
Thanks!
When running multiple tests in parallel the database of
phpunit-clever-and-smart
might locked for a short moment. Sometimes this leads to phpunit aborting execution.Here's the error message with stack trace:
Maybe we can change this behaviour to "wait a second and try again" or at least to ignore this exception (maybe print a warning to stderr).