Skip to content

Commit 74b4718

Browse files
houshiancopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 903207915
1 parent e98ae66 commit 74b4718

2 files changed

Lines changed: 106 additions & 2 deletions

File tree

src/javatests/com/google/devtools/mobileharness/infra/client/api/mode/local/LocalModeIntegrationTest.java

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
21+
import static com.google.devtools.mobileharness.shared.util.truth.Correspondences.isInstanceOf;
2122

2223
import com.google.common.collect.ImmutableList;
2324
import com.google.common.collect.ImmutableMap;
@@ -43,6 +44,7 @@
4344
import com.google.inject.testing.fieldbinder.Bind;
4445
import com.google.inject.testing.fieldbinder.BoundFieldModule;
4546
import com.google.wireless.qa.mobileharness.shared.api.device.Device;
47+
import com.google.wireless.qa.mobileharness.shared.controller.event.LocalTestStartedEvent;
4648
import com.google.wireless.qa.mobileharness.shared.controller.event.LocalTestStartingEvent;
4749
import com.google.wireless.qa.mobileharness.shared.model.job.JobInfo;
4850
import com.google.wireless.qa.mobileharness.shared.model.job.JobLocator;
@@ -53,6 +55,8 @@
5355
import com.google.wireless.qa.mobileharness.shared.proto.query.DeviceQuery;
5456
import com.google.wireless.qa.mobileharness.shared.proto.query.DeviceQuery.DeviceQueryFilter;
5557
import java.time.Duration;
58+
import java.util.ArrayList;
59+
import java.util.List;
5660
import java.util.UUID;
5761
import org.junit.Before;
5862
import 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
}

src/javatests/com/google/devtools/mobileharness/shared/util/truth/Correspondences.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public class Correspondences {
3838
},
3939
"contains all elements in");
4040

41+
private static final Correspondence<Object, Class<?>> IS_INSTANCE_OF =
42+
Correspondence.from(
43+
(actual, expected) -> requireNonNull(expected).isInstance(actual), "is instance of");
44+
4145
private static final Correspondence<String, String> STARTS_WITH =
4246
Correspondence.from(
4347
(actual, expected) -> requireNonNull(actual).startsWith(requireNonNull(expected)),
@@ -51,6 +55,10 @@ public static Correspondence<String, List<String>> containsAll() {
5155
return CONTAINS_ALL;
5256
}
5357

58+
public static Correspondence<Object, Class<?>> isInstanceOf() {
59+
return IS_INSTANCE_OF;
60+
}
61+
5462
public static Correspondence<String, String> startsWith() {
5563
return STARTS_WITH;
5664
}

0 commit comments

Comments
 (0)