Define TestRule that manages cache use in tests

All current tests that use caches with custom data expiry values
now restore the default config when teardown. We need to prevent
new unsafe uses from being introduced.

Restoration code have also been added to a few other tests that modifies
static fields.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=228888041
This commit is contained in:
weiminyu 2019-01-11 08:44:21 -08:00 committed by Ben McIlwain
parent a6476862fd
commit a80a44cd06
12 changed files with 231 additions and 53 deletions

View file

@ -79,9 +79,7 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
private static final long serialVersionUID = 1455544013508953083L;
@NonFinalForTesting
@VisibleForTesting
static DnsQueue dnsQueue = DnsQueue.create();
@NonFinalForTesting private static DnsQueue dnsQueue = DnsQueue.create();
private final ImmutableSet<String> tlds;
@ -109,5 +107,12 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
getContext().incrementCounter("domains on non-targeted TLDs skipped");
}
}
@VisibleForTesting
public static DnsQueue setDnsQueueForTest(DnsQueue testQueue) {
DnsQueue currentQueue = dnsQueue;
dnsQueue = testQueue;
return currentQueue;
}
}
}