mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Make DoS test case possibly less flaky
This commit is contained in:
parent
5a282c5e05
commit
e9b9fa23fd
|
@ -29,8 +29,9 @@ public final class DoSTrackerTestCase extends Assert {
|
||||||
@Test
|
@Test
|
||||||
public void testDoS() throws Exception {
|
public void testDoS() throws Exception {
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
long timerTimeMS = 200;
|
long timerTimeMS = 500;
|
||||||
DoSTracker tracker = new DoSTracker(timer, 2, timerTimeMS, 3);
|
int maxAccessPerTime = 2;
|
||||||
|
DoSTracker tracker = new DoSTracker(timer, maxAccessPerTime, timerTimeMS, 3);
|
||||||
|
|
||||||
// 2 requests allowed per time; 3rd should be banned
|
// 2 requests allowed per time; 3rd should be banned
|
||||||
assertFalse(tracker.isBanned("A"));
|
assertFalse(tracker.isBanned("A"));
|
||||||
|
@ -49,10 +50,9 @@ public final class DoSTrackerTestCase extends Assert {
|
||||||
Thread.sleep(timerTimeMS * 3);
|
Thread.sleep(timerTimeMS * 3);
|
||||||
assertFalse(tracker.isBanned("A"));
|
assertFalse(tracker.isBanned("A"));
|
||||||
|
|
||||||
assertFalse(tracker.isBanned("A"));
|
|
||||||
// Build up a lot of hits
|
// Build up a lot of hits
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < maxAccessPerTime * 5; i++) {
|
||||||
assertTrue(tracker.isBanned("A"));
|
tracker.isBanned("A");
|
||||||
}
|
}
|
||||||
// After one interval, should still have enough hits to be banned
|
// After one interval, should still have enough hits to be banned
|
||||||
Thread.sleep(timerTimeMS * 2);
|
Thread.sleep(timerTimeMS * 2);
|
||||||
|
|
Loading…
Reference in a new issue