Permalink
Browse files

Make DoS test case possibly less flaky

  • Loading branch information...
srowen committed Sep 22, 2018
1 parent 5a282c5 commit e9b9fa23fd477fc3b45a218f3809bd3e578a99e8
Showing with 5 additions and 5 deletions.
  1. +5 −5 zxingorg/src/test/java/com/google/zxing/web/DoSTrackerTestCase.java
@@ -29,8 +29,9 @@
@Test
public void testDoS() throws Exception {
Timer timer = new Timer();
long timerTimeMS = 200;
DoSTracker tracker = new DoSTracker(timer, 2, timerTimeMS, 3);
long timerTimeMS = 500;
int maxAccessPerTime = 2;
DoSTracker tracker = new DoSTracker(timer, maxAccessPerTime, timerTimeMS, 3);
// 2 requests allowed per time; 3rd should be banned
assertFalse(tracker.isBanned("A"));
@@ -49,10 +50,9 @@ public void testDoS() throws Exception {
Thread.sleep(timerTimeMS * 3);
assertFalse(tracker.isBanned("A"));
assertFalse(tracker.isBanned("A"));
// Build up a lot of hits
for (int i = 0; i < 10; i++) {
assertTrue(tracker.isBanned("A"));
for (int i = 0; i < maxAccessPerTime * 5; i++) {
tracker.isBanned("A");
}
// After one interval, should still have enough hits to be banned
Thread.sleep(timerTimeMS * 2);

0 comments on commit e9b9fa2

Please sign in to comment.