Skip to content

Commit

Permalink
Reduce timeout time to 1 minute
Browse files Browse the repository at this point in the history
  • Loading branch information
a-a-hofmann committed Oct 2, 2019
1 parent 71bec09 commit 5d7c263
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean existsByUserIdAndHasNoResultOrConsoleNotOlderThan10min(String use
.where("userId").is(userId)
.and("console").exists(false)
.and("result").exists(false)
.and("timestamp").gt(Instant.now().minus(10, ChronoUnit.MINUTES)));
.and("timestamp").gt(Instant.now().minus(1, ChronoUnit.MINUTES)));
return mongoTemplate.exists(query, StudentSubmission.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,56 @@ public void userRateLimitedWithOldSubmission() {
boolean userRateLimited = service.isUserRateLimited(userId);
Assertions.assertThat(userRateLimited).isFalse();
}

@Test
public void userRateLimitedWithOldSubmissionMinutes() {
String userId = "123";
submissionProperties.setUserRateLimit(true);
CodeSubmission submission = CodeSubmission.builder()
.userId(userId)
.timestamp(Instant.now().minus(1, ChronoUnit.MINUTES))
.build();
repository.save(submission);
boolean userRateLimited = service.isUserRateLimited(userId);
Assertions.assertThat(userRateLimited).isFalse();
}

@Test
public void userRateLimitedWithOldSubmissionSeconds() {
String userId = "123";
submissionProperties.setUserRateLimit(true);
CodeSubmission submission = CodeSubmission.builder()
.userId(userId)
.timestamp(Instant.now().minus(59, ChronoUnit.SECONDS))
.build();
repository.save(submission);
boolean userRateLimited = service.isUserRateLimited(userId);
Assertions.assertThat(userRateLimited).isTrue();
}

@Test
public void userRateLimitedWithOldSubmission1Minute() {
String userId = "123";
submissionProperties.setUserRateLimit(true);
CodeSubmission submission = CodeSubmission.builder()
.userId(userId)
.timestamp(Instant.now().minus(60, ChronoUnit.SECONDS))
.build();
repository.save(submission);
boolean userRateLimited = service.isUserRateLimited(userId);
Assertions.assertThat(userRateLimited).isFalse();
}

@Test
public void userRateLimitedWithOldSubmission1Minute1Second() {
String userId = "123";
submissionProperties.setUserRateLimit(true);
CodeSubmission submission = CodeSubmission.builder()
.userId(userId)
.timestamp(Instant.now().minus(61, ChronoUnit.SECONDS))
.build();
repository.save(submission);
boolean userRateLimited = service.isUserRateLimited(userId);
Assertions.assertThat(userRateLimited).isFalse();
}
}

0 comments on commit 5d7c263

Please sign in to comment.