Use different timeouts based on whether event is expected to occur
Before this change, the test waited for 500 ms in the cases where the
input devices were expected to change, and also in the cases where the
input devices were not expected to change.
When a device is being added, this timeout is way too short for some
hardware. This causes test flakiness. However, we can't directly
increase this timeout, because it would make the tests slower, since the
same value will be used for the case where input devices are not
expected to change.
Therefore, in this CL, we provide a way for the caller to specify the
timeout, and introduce a new, shorter timeout for the cases where the
event is not expected to occur.
This is a speculative fix.
Bug: 332178280
Change-Id: I6ee5b75a1331c41544b3efa4c408964eeb512551
Flag: TEST_ONLY
Test: atest inputflinger_tests
diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.cpp b/services/inputflinger/tests/FakeInputReaderPolicy.cpp
index d77d539..e1f844c 100644
--- a/services/inputflinger/tests/FakeInputReaderPolicy.cpp
+++ b/services/inputflinger/tests/FakeInputReaderPolicy.cpp
@@ -32,19 +32,23 @@
} // namespace
void FakeInputReaderPolicy::assertInputDevicesChanged() {
- waitForInputDevices([](bool devicesChanged) {
- if (!devicesChanged) {
- FAIL() << "Timed out waiting for notifyInputDevicesChanged() to be called.";
- }
- });
+ waitForInputDevices(
+ [](bool devicesChanged) {
+ if (!devicesChanged) {
+ FAIL() << "Timed out waiting for notifyInputDevicesChanged() to be called.";
+ }
+ },
+ ADD_INPUT_DEVICE_TIMEOUT);
}
void FakeInputReaderPolicy::assertInputDevicesNotChanged() {
- waitForInputDevices([](bool devicesChanged) {
- if (devicesChanged) {
- FAIL() << "Expected notifyInputDevicesChanged() to not be called.";
- }
- });
+ waitForInputDevices(
+ [](bool devicesChanged) {
+ if (devicesChanged) {
+ FAIL() << "Expected notifyInputDevicesChanged() to not be called.";
+ }
+ },
+ INPUT_DEVICES_DIDNT_CHANGE_TIMEOUT);
}
void FakeInputReaderPolicy::assertStylusGestureNotified(int32_t deviceId) {
@@ -261,13 +265,13 @@
return "";
}
-void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged) {
+void FakeInputReaderPolicy::waitForInputDevices(std::function<void(bool)> processDevicesChanged,
+ std::chrono::milliseconds timeout) {
std::unique_lock<std::mutex> lock(mLock);
base::ScopedLockAssertion assumeLocked(mLock);
const bool devicesChanged =
- mDevicesChangedCondition.wait_for(lock,
- ADD_INPUT_DEVICE_TIMEOUT * HW_TIMEOUT_MULTIPLIER,
+ mDevicesChangedCondition.wait_for(lock, timeout * HW_TIMEOUT_MULTIPLIER,
[this]() REQUIRES(mLock) {
return mInputDevicesChanged;
});