1
1
mirror of https://github.com/MarginaliaSearch/MarginaliaSearch.git synced 2025-10-05 21:22:39 +02:00
Files
Viktor Lofgren 9eb16cb667 (test) Remove tests from fast suite
Adding a new @Tag("flaky") for tests that do not reliably return successes.  These may still be valuable during development, but should not run in CI.

Also tagging a few of the slower tests with the old @Tag("slow"), to speed up the run-time.
2024-11-17 19:45:59 +01:00

56 lines
1.5 KiB
Java

package nu.marginalia.api.svc;
import nu.marginalia.api.model.ApiLicense;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@Tag("flaky")
class RateLimiterServiceTest {
RateLimiterService rateLimiterService;
@BeforeEach
public void setUp() {
rateLimiterService = new RateLimiterService();
}
@AfterEach
public void tearDown() {
rateLimiterService.clear();
}
@Test
public void testNoLimit() {
var license = new ApiLicense("key", "Public Domain", "Steven", 0);
for (int i = 0; i < 10000; i++) {
assertTrue(rateLimiterService.isAllowed(license));
}
// No rate limiter is created when rate is <= 0
assertEquals(0, rateLimiterService.size());
}
@Test
public void testWithLimit() {
var license = new ApiLicense("key", "Public Domain", "Steven", 10);
var otherLicense = new ApiLicense("key2", "Public Domain", "Bob", 10);
for (int i = 0; i < 1000; i++) {
if (i < 10) {
assertTrue(rateLimiterService.isAllowed(license));
}
else {
assertFalse(rateLimiterService.isAllowed(license));
}
}
assertTrue(rateLimiterService.isAllowed(otherLicense));
assertEquals(2, rateLimiterService.size());
}
}