Skip to content

Commit

Permalink
Speedup slow tests due to rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
KENNYSOFT committed Sep 19, 2024
1 parent d5e0036 commit 9cd4793
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.slack.api.Slack;
import com.slack.api.SlackConfig;
import com.slack.api.methods.MethodsConfig;
import com.slack.api.methods.MethodsCustomRateLimitResolver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import util.MockSlackApiServer;

import java.util.Optional;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static util.MockSlackApi.ValidToken;
Expand All @@ -21,6 +25,19 @@ public class TeamTest {
public void setup() throws Exception {
server.start();
config.setMethodsEndpointUrlPrefix(server.getMethodsEndpointPrefix());
MethodsConfig methodsConfig = new MethodsConfig();
methodsConfig.setCustomRateLimitResolver(new MethodsCustomRateLimitResolver() {
@Override
public Optional<Integer> getCustomAllowedRequestsPerMinute(String teamId, String methodName) {
return Optional.of(20);
}

@Override
public Optional<Integer> getCustomAllowedRequestsForChatPostMessagePerMinute(String teamId, String channel) {
return Optional.empty();
}
});
config.setMethodsConfig(methodsConfig);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.slack.api.Slack;
import com.slack.api.SlackConfig;
import com.slack.api.methods.AsyncMethodsClient;
import com.slack.api.methods.MethodsConfig;
import com.slack.api.methods.MethodsCustomRateLimitResolver;
import com.slack.api.model.admin.AppConfig;
import org.junit.After;
import org.junit.Before;
Expand All @@ -11,6 +13,7 @@

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Optional;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -26,6 +29,19 @@ public class AdminApiAsyncTest {
public void setup() throws Exception {
server.start();
config.setMethodsEndpointUrlPrefix(server.getMethodsEndpointPrefix());
MethodsConfig methodsConfig = new MethodsConfig();
methodsConfig.setCustomRateLimitResolver(new MethodsCustomRateLimitResolver() {
@Override
public Optional<Integer> getCustomAllowedRequestsPerMinute(String teamId, String methodName) {
return Optional.of(50);
}

@Override
public Optional<Integer> getCustomAllowedRequestsForChatPostMessagePerMinute(String teamId, String channel) {
return Optional.empty();
}
});
config.setMethodsConfig(methodsConfig);
}

@After
Expand Down

0 comments on commit 9cd4793

Please sign in to comment.