Skip to content

Commit

Permalink
Merge pull request #315 from mp-access/improvement/submission-timeout
Browse files Browse the repository at this point in the history
Hotfix: Reduce submission timeout time to 1 minute
  • Loading branch information
a-a-hofmann authored Oct 2, 2019
2 parents fc5b46c + 5d7c263 commit 62d9ae2
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 62d9ae2

Please sign in to comment.