Skip to content
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

Provide a way to reset a LockStore between tests #54409

Open
VincentLanglet opened this issue Mar 26, 2024 · 2 comments
Open

Provide a way to reset a LockStore between tests #54409

VincentLanglet opened this issue Mar 26, 2024 · 2 comments

Comments

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Mar 26, 2024

Description

Maybe I missed some things but I didn't find an easy way to reset a LockStore.

If I run

$lock = $this->lockFactory->createLock('foo', 60, false);
$isAcquired = $lock->acquire();

and I run my tests two times, I get true first time and false second time.

I would look for an easy way to "clear" locks between tests runs.

Of course the issue doesn't occur with $this->lockFactory->createLock('foo', 60, true); since the lock is autoreleased.

In the same way there is

  • BlockingStoreInterface
  • SharedLockStoreInterface
  • PersistingStoreInterface

What about something like a ClearableStoreInterface ?
There is also a need for a way to access store in tests...

Example

For instance, MemcachStore would implement

public function clear(): void
{
    $this->memcached->flush();
}
@stof
Copy link
Member

stof commented Mar 26, 2024

your suggested change for MemcacheStore still assumes that the lock store is the only consumer of the whole Memcache instance (so that clearing the memcache instance does not remove other things than locks).
And if this is only something useful for tests (which I think is the case as clearing the lock store basically breaks the behavior of the lock), I think it might be better for your test to reach directly to the lower-level layer (or to avoid using a persistent lock storage depending on the kind of tests)

@VincentLanglet
Copy link
Contributor Author

VincentLanglet commented Mar 26, 2024

(or to avoid using a persistent lock storage depending on the kind of tests)

The issue I encounter with this is that the autorelease: false param is useless for such store when writing tests with multiple request.

I think it might be better for your test to reach directly to the lower-level layer

Sure, I would have expect some helpers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants