mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Increase RDAP unit test speed
There's no reason to have to create 2,500 simulated database entities for a single test (which makes it take a really long time). Better to just set the relevant limit to be lower for testing purposes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=202120722
This commit is contained in:
parent
44c517f111
commit
07aead3ca4
2 changed files with 28 additions and 30 deletions
|
@ -47,6 +47,7 @@ import google.registry.request.Parameter;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.Idn;
|
import google.registry.util.Idn;
|
||||||
|
import google.registry.util.NonFinalForTesting;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -73,11 +74,12 @@ import org.joda.time.DateTime;
|
||||||
)
|
)
|
||||||
public class RdapDomainSearchAction extends RdapSearchActionBase {
|
public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||||
|
|
||||||
public static final String PATH = "/rdap/domains";
|
static final String PATH = "/rdap/domains";
|
||||||
|
|
||||||
public static final int RESULT_SET_SIZE_SCALING_FACTOR = 30;
|
static final int RESULT_SET_SIZE_SCALING_FACTOR = 30;
|
||||||
|
|
||||||
public static final int MAX_NAMESERVERS_IN_FIRST_STAGE = 300;
|
@NonFinalForTesting
|
||||||
|
static int maxNameserversInFirstStage = 300;
|
||||||
|
|
||||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||||
|
|
||||||
|
@ -319,7 +321,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||||
// must be present, to avoid querying every host in the system. This restriction is enforced by
|
// must be present, to avoid querying every host in the system. This restriction is enforced by
|
||||||
// {@link queryItems}.
|
// {@link queryItems}.
|
||||||
//
|
//
|
||||||
// Only return the first MAX_NAMESERVERS_IN_FIRST_STAGE nameservers. This could result in an
|
// Only return the first maxNameserversInFirstStage nameservers. This could result in an
|
||||||
// incomplete result set if a search asks for something like "ns*", but we need to enforce a
|
// incomplete result set if a search asks for something like "ns*", but we need to enforce a
|
||||||
// limit in order to avoid arbitrarily long-running queries.
|
// limit in order to avoid arbitrarily long-running queries.
|
||||||
Query<HostResource> query =
|
Query<HostResource> query =
|
||||||
|
@ -328,7 +330,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||||
"fullyQualifiedHostName",
|
"fullyQualifiedHostName",
|
||||||
partialStringQuery,
|
partialStringQuery,
|
||||||
DeletedItemHandling.EXCLUDE,
|
DeletedItemHandling.EXCLUDE,
|
||||||
MAX_NAMESERVERS_IN_FIRST_STAGE);
|
maxNameserversInFirstStage);
|
||||||
Optional<String> desiredRegistrar = getDesiredRegistrar();
|
Optional<String> desiredRegistrar = getDesiredRegistrar();
|
||||||
if (desiredRegistrar.isPresent()) {
|
if (desiredRegistrar.isPresent()) {
|
||||||
query = query.filter("currentSponsorClientId", desiredRegistrar.get());
|
query = query.filter("currentSponsorClientId", desiredRegistrar.get());
|
||||||
|
@ -416,7 +418,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||||
* <p>In theory, we could have any number of hosts using the same IP address. To make sure we get
|
* <p>In theory, we could have any number of hosts using the same IP address. To make sure we get
|
||||||
* all the associated domains, we have to retrieve all of them, and use them to look up domains.
|
* all the associated domains, we have to retrieve all of them, and use them to look up domains.
|
||||||
* This could open us up to a kind of DoS attack if huge number of hosts are defined on a single
|
* This could open us up to a kind of DoS attack if huge number of hosts are defined on a single
|
||||||
* IP. To avoid this, fetch only the first {@link #MAX_NAMESERVERS_IN_FIRST_STAGE} nameservers. In
|
* IP. To avoid this, fetch only the first {@link #maxNameserversInFirstStage} nameservers. In
|
||||||
* all normal circumstances, this should be orders of magnitude more than there actually are. But
|
* all normal circumstances, this should be orders of magnitude more than there actually are. But
|
||||||
* it could result in us missing some domains.
|
* it could result in us missing some domains.
|
||||||
*
|
*
|
||||||
|
@ -433,7 +435,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
DeletedItemHandling.EXCLUDE,
|
DeletedItemHandling.EXCLUDE,
|
||||||
MAX_NAMESERVERS_IN_FIRST_STAGE);
|
maxNameserversInFirstStage);
|
||||||
Optional<String> desiredRegistrar = getDesiredRegistrar();
|
Optional<String> desiredRegistrar = getDesiredRegistrar();
|
||||||
if (desiredRegistrar.isPresent()) {
|
if (desiredRegistrar.isPresent()) {
|
||||||
query = query.filter("currentSponsorClientId", desiredRegistrar.get());
|
query = query.filter("currentSponsorClientId", desiredRegistrar.get());
|
||||||
|
@ -494,7 +496,7 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
|
||||||
// so, indicate the result might be incomplete.
|
// so, indicate the result might be incomplete.
|
||||||
return makeSearchResults(
|
return makeSearchResults(
|
||||||
domains,
|
domains,
|
||||||
(numHostKeysSearched >= MAX_NAMESERVERS_IN_FIRST_STAGE)
|
(numHostKeysSearched >= maxNameserversInFirstStage)
|
||||||
? IncompletenessWarningType.MIGHT_BE_INCOMPLETE
|
? IncompletenessWarningType.MIGHT_BE_INCOMPLETE
|
||||||
: IncompletenessWarningType.COMPLETE,
|
: IncompletenessWarningType.COMPLETE,
|
||||||
(numHostKeysSearched > 0) ? Optional.of((long) domains.size()) : Optional.empty(),
|
(numHostKeysSearched > 0) ? Optional.of((long) domains.size()) : Optional.empty(),
|
||||||
|
|
|
@ -87,13 +87,9 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class RdapDomainSearchActionTest extends RdapSearchActionTestCase {
|
public class RdapDomainSearchActionTest extends RdapSearchActionTestCase {
|
||||||
|
|
||||||
@Rule
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
||||||
.withDatastore()
|
|
||||||
.build();
|
|
||||||
|
|
||||||
@Rule
|
@Rule public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01T00:00:00Z"));
|
||||||
|
@ -176,6 +172,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
RdapDomainSearchAction.maxNameserversInFirstStage = 40;
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
|
|
||||||
// cat.lol and cat2.lol
|
// cat.lol and cat2.lol
|
||||||
|
@ -1761,16 +1758,16 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameserverMatchManyNameserversForTheSameDomainsWithSuffix() {
|
public void testNameserverMatchManyNameserversForTheSameDomainsWithSuffix() {
|
||||||
// Same as above, except that we find all 40 nameservers because of the wildcard. But we
|
// Same as above, except that we find all 39 nameservers because of the wildcard. But we
|
||||||
// should still only return 3 domains, because we merge duplicate domains together in a set.
|
// should still only return 3 domains, because we merge duplicate domains together in a set.
|
||||||
// Since we fetch domains by nameserver in batches of 30 nameservers, we need to make sure to
|
// Since we fetch domains by nameserver in batches of 30 nameservers, we need to make sure to
|
||||||
// have more than that number of nameservers for an effective test.
|
// have more than that number of nameservers for an effective test.
|
||||||
createManyDomainsAndHosts(3, 1, 40);
|
createManyDomainsAndHosts(3, 1, 39);
|
||||||
rememberWildcardType("ns*.domain1.lol");
|
rememberWildcardType("ns*.domain1.lol");
|
||||||
Object obj = generateActualJson(RequestType.NS_LDH_NAME, "ns*.domain1.lol");
|
Object obj = generateActualJson(RequestType.NS_LDH_NAME, "ns*.domain1.lol");
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
checkNumberOfDomainsInResult(obj, 3);
|
checkNumberOfDomainsInResult(obj, 3);
|
||||||
verifyMetrics(SearchType.BY_NAMESERVER_NAME, Optional.of(3L), Optional.of(40L));
|
verifyMetrics(SearchType.BY_NAMESERVER_NAME, Optional.of(3L), Optional.of(39L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1827,37 +1824,36 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameserverMatch_duplicatesNotTruncated() {
|
public void testNameserverMatch_duplicatesNotTruncated() {
|
||||||
// 60 nameservers for each of 4 domains; these should translate into 2 30-nameserver domain
|
// 36 nameservers for each of 4 domains; these should translate into two fetches, which should
|
||||||
// fetches, which should _not_ trigger the truncation warning because all the domains will be
|
// not trigger the truncation warning because all the domains will be duplicates.
|
||||||
// duplicates.
|
createManyDomainsAndHosts(4, 1, 36);
|
||||||
createManyDomainsAndHosts(4, 1, 60);
|
|
||||||
rememberWildcardType("ns*.domain1.lol");
|
rememberWildcardType("ns*.domain1.lol");
|
||||||
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns*.domain1.lol"))
|
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns*.domain1.lol"))
|
||||||
.isEqualTo(readMultiDomainFile(
|
.isEqualTo(readMultiDomainFile(
|
||||||
"rdap_nontruncated_domains.json",
|
"rdap_nontruncated_domains.json",
|
||||||
"domain1.lol",
|
"domain1.lol",
|
||||||
"BA-LOL",
|
"8A-LOL",
|
||||||
"domain2.lol",
|
"domain2.lol",
|
||||||
"B9-LOL",
|
"89-LOL",
|
||||||
"domain3.lol",
|
"domain3.lol",
|
||||||
"B8-LOL",
|
"88-LOL",
|
||||||
"domain4.lol",
|
"domain4.lol",
|
||||||
"B7-LOL"));
|
"87-LOL"));
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
verifyMetrics(SearchType.BY_NAMESERVER_NAME, Optional.of(4L), Optional.of(60L));
|
verifyMetrics(SearchType.BY_NAMESERVER_NAME, Optional.of(4L), Optional.of(36L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameserverMatch_incompleteResultsSet() {
|
public void testNameserverMatch_incompleteResultsSet() {
|
||||||
createManyDomainsAndHosts(2, 1, 2500);
|
createManyDomainsAndHosts(2, 1, 41);
|
||||||
rememberWildcardType("ns*.domain1.lol");
|
rememberWildcardType("ns*.domain1.lol");
|
||||||
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns*.domain1.lol"))
|
assertThat(generateActualJson(RequestType.NS_LDH_NAME, "ns*.domain1.lol"))
|
||||||
.isEqualTo(readMultiDomainFile(
|
.isEqualTo(readMultiDomainFile(
|
||||||
"rdap_incomplete_domains.json",
|
"rdap_incomplete_domains.json",
|
||||||
"domain1.lol",
|
"domain1.lol",
|
||||||
"13C8-LOL",
|
"92-LOL",
|
||||||
"domain2.lol",
|
"domain2.lol",
|
||||||
"13C7-LOL",
|
"91-LOL",
|
||||||
"x",
|
"x",
|
||||||
"x",
|
"x",
|
||||||
"x",
|
"x",
|
||||||
|
@ -1866,7 +1862,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase {
|
||||||
verifyMetrics(
|
verifyMetrics(
|
||||||
SearchType.BY_NAMESERVER_NAME,
|
SearchType.BY_NAMESERVER_NAME,
|
||||||
Optional.of(2L),
|
Optional.of(2L),
|
||||||
Optional.of(2500L),
|
Optional.of(41L),
|
||||||
IncompletenessWarningType.MIGHT_BE_INCOMPLETE);
|
IncompletenessWarningType.MIGHT_BE_INCOMPLETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue