Skip to content

[KernelTest][RateLimiter] Provide a way to reset RateLimiter in tests #48021

Closed
@nfragnet

Description

@nfragnet

Description

Hello !

I faced the following issue: while writing API tests, results of some of my tests were relying on RateLimiter state.
In order to be able to parallelize my tests and running them in any order, I need to be sure that the RateLimiter is reset before each test using it.

The RateLimiter does not provide a simple way to be reset itself, so I ended up clearing rate limiter pool cache manually in my tests.

This is the solution I setup for my personal need.

Just wanted to know if a more global use could be relevant, have your feedbacks and maybe open a PR it worths it.

Example

trait ResetRateLimiterTrait
{
    protected static function resetRateLimiter(): void
    {
        static::getContainer()->get('cache.global_clearer')->clearPool('cache.rate_limiter');
    }
}

class PurchaseApiTest extends ApiTestCase
{
    use ResetRateLimiterTrait;

    protected function setUp(): void
    {
        parent::setUp();
        static::resetRateLimiter();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions