Only inject EPP metric builder in a single place

This fixes recording of number of attempts and command name on EPP
flows, which was broken because a separate metric builder was
being injected in two places, EppController and FlowRunner, with the
one injected into FlowRunner being discarded rather than having changes
applied to the same instance as in EppController.

This also adds a test that the metric is created successfully inside
a flow. Note that tests already exist for EppController to ensure that
the metric is recorded correctly.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152306596
This commit is contained in:
mcilwain 2017-04-05 14:35:28 -07:00 committed by Ben McIlwain
parent 794743c7bc
commit 4606b1d08e
7 changed files with 58 additions and 36 deletions

View file

@ -15,6 +15,7 @@
package google.registry.flows;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Sets.difference;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.marshal;
@ -46,6 +47,7 @@ import google.registry.model.ofy.Ofy;
import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.tmch.ClaimsListShard.ClaimsListSingleton;
import google.registry.monitoring.whitebox.EppMetric;
import google.registry.testing.AppEngineRule;
import google.registry.testing.EppLoader;
import google.registry.testing.ExceptionRule;
@ -96,6 +98,8 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
protected TransportCredentials credentials = new PasswordOnlyTransportCredentials();
protected EppRequestSource eppRequestSource = EppRequestSource.UNIT_TEST;
private EppMetric.Builder eppMetricBuilder;
@Before
public void init() throws Exception {
sessionMetadata = new HttpSessionMetadata(new FakeHttpSession());
@ -123,6 +127,11 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
return eppLoader.getEpp();
}
protected EppMetric getEppMetric() {
checkNotNull(eppMetricBuilder, "Run the flow first before checking EPP metrics");
return eppMetricBuilder.build();
}
protected String readFile(String filename) {
return readResourceUtf8(getClass(), "testdata/" + filename);
}
@ -273,6 +282,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
private EppOutput runFlowInternal(CommitMode commitMode, UserPrivileges userPrivileges)
throws Exception {
eppMetricBuilder = EppMetric.builderForRequest("request-id-1", clock);
// Assert that the xml triggers the flow we expect.
assertThat(FlowPicker.getFlowClass(eppLoader.getEpp()))
.isEqualTo(new TypeInstantiator<F>(getClass()){}.getExactType());
@ -293,7 +303,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
.build())
.build()
.flowRunner()
.run();
.run(eppMetricBuilder);
}
/** Run a flow and marshal the result to EPP, or throw if it doesn't validate. */