mirror of
https://github.com/google/nomulus
synced 2026-09-10 01:56:11 +00:00
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:
@@ -34,6 +34,7 @@ import google.registry.testing.InjectRule;
|
||||
import google.registry.util.RequestStatusChecker;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -50,6 +51,8 @@ public class LockTest {
|
||||
private static final RequestStatusChecker requestStatusChecker = mock(RequestStatusChecker.class);
|
||||
private static final FakeClock clock = new FakeClock();
|
||||
|
||||
private LockMetrics origLockMetrics;
|
||||
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
@Rule public final InjectRule inject = new InjectRule();
|
||||
|
||||
@@ -73,11 +76,17 @@ public class LockTest {
|
||||
|
||||
@Before public void setUp() {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
origLockMetrics = Lock.lockMetrics;
|
||||
Lock.lockMetrics = null;
|
||||
when(requestStatusChecker.getLogId()).thenReturn("current-request-id");
|
||||
when(requestStatusChecker.isRunning("current-request-id")).thenReturn(true);
|
||||
}
|
||||
|
||||
@After
|
||||
public void restoreLockMetric() {
|
||||
Lock.lockMetrics = origLockMetrics;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleasedExplicitly() {
|
||||
Optional<Lock> lock = acquire("", ONE_DAY, FREE);
|
||||
|
||||
Reference in New Issue
Block a user