-
-
Notifications
You must be signed in to change notification settings - Fork 73
Allow to acquire multiple locks #201
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
Conversation
|
Why do you need multiple locks? |
|
In my case one for database (to prevent parallel accesses to database) and second for testing API server (also to prevent parellel access to API). Some tests need just database, some needs just API but some needs both. |
|
Ok, that makes sense. |
Tester/Framework/Environment.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinMystikJonas Can you remove the initialization? No big deal, it's just shorter.
|
@MartinMystikJonas And can you rename the commit? Something like |
7effe50 to
f4372ee
Compare
|
@milo Done. |
|
@MartinMystikJonas Thank you! |
|
Hi. Are you really sure this is a good idea? I don't know the original use case, but with this commit is even very simple test failing (based on sandbox default test case): <?php
namespace Test;
use Nette,
Tester,
Tester\Assert;
$container = require __DIR__ . '/bootstrap.php';
class ExampleTest extends Tester\TestCase {
private $container;
function __construct(Nette\DI\Container $container) {
$this->container = $container;
}
function setUp() {
Tester\Environment::lock('db', __DIR__);
}
function testSomething1() {
Assert::true( true );
}
function testSomething2() {
Assert::true( true );
}
}
$test = new ExampleTest($container);
$test->run();Well it's actually not failing, it freezes... |
|
The lock is never released, because you're not running the test case in multiple processes. To run the test case in multiple processes you have to add |
|
It's not true. I have every testcase with this annotation. This example also doesn't work with the |
Contents of static $locks exists only in one process. The acquiring can be skipped when lock already exists in this process.
|
@mrtnzlml Are you sure you use |
|
@milo Yeah, I understood the request and it make sense. But the implementation was odd and I wasn't able to run all tests without freeze. Oh sorry. It actually works with this annotation. It doesn't work only in my project (that's why I reported this behavior). But to be honest I am not sure if it actually run in 8 threads or not. Apparently not. @fprochazka What did you mean with "You should use different names."? |
|
Easy to check. Run |
|
Yeah I know that and it returns more dots (which is not very good test :-)). But still it doesn't work with the annotation. But I am not very good in testing and it works well with your patch, so - problem solved I guess. Thanks. |
In current implementation when Environment::lock is called multiple times only last acquired lock is saved. Previous lock are sometimes randomly garbage collected. This results in race conditions and random test failures.