mirror of
https://github.com/google/nomulus.git
synced 2025-08-03 00:12:11 +02:00
Remove unnecessary MockitoExtension from Spec11PipelineTest (#1115)
* Remove unnecessary MockitoExtension from Spec11PipelineTest This is kind of a shot in the dark here, but this is one of the obvious differences between this test class (which frequently experiences flakes) and the other pipeline test classes which do not. It's also possible we were getting the wrong runner if the test framework was incorrectly detecting an App Engine runtime environment, so I added an assert that will make it very clear if this is the cause of any failures.
This commit is contained in:
parent
d285edef3d
commit
cb16df235a
1 changed files with 27 additions and 6 deletions
|
@ -16,6 +16,7 @@ package google.registry.beam.spec11;
|
|||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.ImmutableObjectSubject.immutableObjectCorrespondence;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
|
||||
|
@ -34,6 +35,7 @@ import google.registry.testing.DatastoreEntityExtension;
|
|||
import google.registry.testing.FakeClock;
|
||||
import google.registry.util.ResourceUtils;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.apache.beam.sdk.coders.KvCoder;
|
||||
|
@ -48,12 +50,8 @@ import org.json.JSONObject;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Spec11Pipeline}.
|
||||
|
@ -62,9 +60,8 @@ import org.mockito.quality.Strictness;
|
|||
* Therefore we cannot fully test the pipeline but only test the two separate sink IO functions,
|
||||
* assuming that date is sourcede correctly the {@code BigQueryIO}.
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.STRICT_STUBS)
|
||||
class Spec11PipelineTest {
|
||||
|
||||
private static final String DATE = "2020-01-27";
|
||||
private static final String SAFE_BROWSING_API_KEY = "api-key";
|
||||
private static final String REPORTING_BUCKET_URL = "reporting_bucket";
|
||||
|
@ -123,6 +120,11 @@ class Spec11PipelineTest {
|
|||
KvCoder.of(
|
||||
SerializableCoder.of(Subdomain.class),
|
||||
SerializableCoder.of(ThreatMatch.class))));
|
||||
assertWithMessage(
|
||||
"Beam pipelines don't run in an App Engine environment, and thus the tests shouldn't be"
|
||||
+ " mocking one either")
|
||||
.that(isAppEngine())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -193,6 +195,25 @@ class Spec11PipelineTest {
|
|||
.containsExactlyElementsIn(expectedFileContents.subList(1, expectedFileContents.size()));
|
||||
}
|
||||
|
||||
// Adapted from Guava's MoreExecutors (where it is a private method)
|
||||
private static boolean isAppEngine() {
|
||||
if (System.getProperty("com.google.appengine.runtime.environment") == null) {
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
return Class.forName("com.google.apphosting.api.ApiProxy")
|
||||
.getMethod("getCurrentEnvironment")
|
||||
.invoke(null)
|
||||
!= null;
|
||||
} catch (ClassNotFoundException
|
||||
| InvocationTargetException
|
||||
| IllegalAccessException
|
||||
| NoSuchMethodException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the text contents of a file under the beamBucket/results directory. */
|
||||
private ImmutableList<String> resultFileContents() throws Exception {
|
||||
File resultFile =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue