1818
1919import static com .google .common .truth .Truth .assertThat ;
2020import static com .google .common .truth .extensions .proto .ProtoTruth .assertThat ;
21+ import static com .google .devtools .mobileharness .shared .util .truth .Correspondences .isInstanceOf ;
2122
2223import com .google .common .collect .ImmutableList ;
2324import com .google .common .collect .ImmutableMap ;
4344import com .google .inject .testing .fieldbinder .Bind ;
4445import com .google .inject .testing .fieldbinder .BoundFieldModule ;
4546import com .google .wireless .qa .mobileharness .shared .api .device .Device ;
47+ import com .google .wireless .qa .mobileharness .shared .controller .event .LocalTestStartedEvent ;
4648import com .google .wireless .qa .mobileharness .shared .controller .event .LocalTestStartingEvent ;
4749import com .google .wireless .qa .mobileharness .shared .model .job .JobInfo ;
4850import com .google .wireless .qa .mobileharness .shared .model .job .JobLocator ;
5355import com .google .wireless .qa .mobileharness .shared .proto .query .DeviceQuery ;
5456import com .google .wireless .qa .mobileharness .shared .proto .query .DeviceQuery .DeviceQueryFilter ;
5557import java .time .Duration ;
58+ import java .util .ArrayList ;
59+ import java .util .List ;
5660import java .util .UUID ;
5761import org .junit .Before ;
5862import org .junit .Rule ;
@@ -105,7 +109,8 @@ public void testDeviceReserver() throws Exception {
105109 JobInfo jobInfo1 = createJobInfo ("fake_job_name_1" );
106110
107111 String allocationKey = "allocation-key-" + UUID .randomUUID ();
108- TestPlugin testPlugin = new TestPlugin (deviceReserver , allocationKey );
112+ TestPluginForDeviceReserver testPlugin =
113+ new TestPluginForDeviceReserver (deviceReserver , allocationKey );
109114
110115 clientApi .startJob (jobInfo1 , localMode , ImmutableList .of (testPlugin ));
111116 clientApi .waitForJob (jobInfo1 .locator ().getId ());
@@ -132,6 +137,44 @@ public void testDeviceReserver() throws Exception {
132137 clientApi .waitForJob (jobInfo2 .locator ().getId ());
133138
134139 assertThat (jobInfo2 .resultWithCause ().get ().type ()).isEqualTo (TestResult .ERROR );
140+
141+ deviceReserver .addTempAllocationKeyToDevice (
142+ new DeviceLocator ("NoOpDevice-0" ), allocationKey , Duration .ZERO );
143+ }
144+
145+ @ Test
146+ public void testTestEvents () throws Exception {
147+ JobInfo jobInfo = createJobInfo ("fake_job_for_test_events" );
148+ TestPluginForTestEvent plugin = new TestPluginForTestEvent ();
149+
150+ clientApi .startJob (jobInfo , localMode , ImmutableList .of (plugin ));
151+ clientApi .waitForJob (jobInfo .locator ().getId ());
152+
153+ assertThat (jobInfo .resultWithCause ().get ().type ()).isEqualTo (TestResult .PASS );
154+ assertThat (plugin .receivedEvents )
155+ .comparingElementsUsing (isInstanceOf ())
156+ .containsExactly (
157+ com .google .devtools .mobileharness .api .testrunner .event .test .TestStartingEvent .class ,
158+ com .google .wireless .qa .mobileharness .shared .controller .event .TestStartingEvent .class ,
159+ com .google .wireless .qa .mobileharness .shared .controller .event .TestStartedEvent .class ,
160+ com .google .devtools .mobileharness .api .testrunner .event .test .TestStartedEvent .class ,
161+ com .google .devtools .mobileharness .api .testrunner .event .test .TestEndingEvent .class ,
162+ com .google .wireless .qa .mobileharness .shared .controller .event .TestEndingEvent .class ,
163+ com .google .wireless .qa .mobileharness .shared .controller .event .TestEndedEvent .class ,
164+ com .google .devtools .mobileharness .api .testrunner .event .test .TestEndedEvent .class )
165+ .inOrder ();
166+ assertThat (plugin .receivedEvents )
167+ .comparingElementsUsing (isInstanceOf ())
168+ .containsExactly (
169+ com .google .devtools .mobileharness .api .testrunner .event .test .TestStartingEvent .class ,
170+ LocalTestStartingEvent .class ,
171+ LocalTestStartedEvent .class ,
172+ com .google .devtools .mobileharness .api .testrunner .event .test .TestStartedEvent .class ,
173+ com .google .devtools .mobileharness .api .testrunner .event .test .LocalTestEndingEvent .class ,
174+ com .google .wireless .qa .mobileharness .shared .controller .event .LocalTestEndingEvent .class ,
175+ com .google .wireless .qa .mobileharness .shared .controller .event .LocalTestEndedEvent .class ,
176+ com .google .devtools .mobileharness .api .testrunner .event .test .LocalTestEndedEvent .class )
177+ .inOrder ();
135178 }
136179
137180 private static JobInfo createJobInfo (String jobName ) {
@@ -152,7 +195,7 @@ private static JobInfo createJobInfo(String jobName) {
152195 return jobInfo ;
153196 }
154197
155- private record TestPlugin (DeviceReserver deviceReserver , String allocationKey ) {
198+ private record TestPluginForDeviceReserver (DeviceReserver deviceReserver , String allocationKey ) {
156199
157200 @ Subscribe
158201 public void onTestStarting (LocalTestStartingEvent event ) throws SkipTestException {
@@ -173,4 +216,57 @@ public void onTestStarting(LocalTestStartingEvent event) throws SkipTestExceptio
173216 }
174217 }
175218 }
219+
220+ private static class TestPluginForTestEvent {
221+
222+ private final List <Object > receivedEvents = new ArrayList <>();
223+
224+ @ Subscribe
225+ public void onTestStarting (
226+ com .google .devtools .mobileharness .api .testrunner .event .test .TestStartingEvent event ) {
227+ receivedEvents .add (event );
228+ }
229+
230+ @ Subscribe
231+ public void onTestStartingOld (
232+ com .google .wireless .qa .mobileharness .shared .controller .event .TestStartingEvent event ) {
233+ receivedEvents .add (event );
234+ }
235+
236+ @ Subscribe
237+ public void onTestStartedOld (
238+ com .google .wireless .qa .mobileharness .shared .controller .event .TestStartedEvent event ) {
239+ receivedEvents .add (event );
240+ }
241+
242+ @ Subscribe
243+ public void onTestStarted (
244+ com .google .devtools .mobileharness .api .testrunner .event .test .TestStartedEvent event ) {
245+ receivedEvents .add (event );
246+ }
247+
248+ @ Subscribe
249+ public void onTestEnding (
250+ com .google .devtools .mobileharness .api .testrunner .event .test .TestEndingEvent event ) {
251+ receivedEvents .add (event );
252+ }
253+
254+ @ Subscribe
255+ public void onTestEndingOld (
256+ com .google .wireless .qa .mobileharness .shared .controller .event .TestEndingEvent event ) {
257+ receivedEvents .add (event );
258+ }
259+
260+ @ Subscribe
261+ public void onTestEndedOld (
262+ com .google .wireless .qa .mobileharness .shared .controller .event .TestEndedEvent event ) {
263+ receivedEvents .add (event );
264+ }
265+
266+ @ Subscribe
267+ public void onTestEnded (
268+ com .google .devtools .mobileharness .api .testrunner .event .test .TestEndedEvent event ) {
269+ receivedEvents .add (event );
270+ }
271+ }
176272}
0 commit comments