diff options
| author | 2024-05-31 14:35:37 +0000 | |
|---|---|---|
| committer | 2024-05-31 15:28:52 +0000 | |
| commit | c2c839d2372f9f9f21ab3653916579a03e989c9b (patch) | |
| tree | d66cdf8789264f3fc3d92e70b77c38175d16563a | |
| parent | e89f7097cc43adb812aecd2f24aa28b4e3572604 (diff) | |
Fix race condition in PointerControllerTest
A previous CL ag/27261516 moved initialisation of thread before the
looper it uses. It introduced a race condition causing tests failures.
This CL changes order of initliation to ensure looper is always
initilised befor the thread.
Bug: 343818855
Test: atest libinputservice_test
Change-Id: Ibcb4d31be6a607f37eeee7207182cdd5eb1d7ead
| -rw-r--r-- | libs/input/tests/PointerController_test.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libs/input/tests/PointerController_test.cpp b/libs/input/tests/PointerController_test.cpp index cbef68e2eb8f..5b00fca4d857 100644 --- a/libs/input/tests/PointerController_test.cpp +++ b/libs/input/tests/PointerController_test.cpp @@ -162,6 +162,16 @@ public: }; class PointerControllerTest : public Test { +private: + void loopThread(); + + std::atomic<bool> mRunning = true; + class MyLooper : public Looper { + public: + MyLooper() : Looper(false) {} + ~MyLooper() = default; + }; + protected: PointerControllerTest(); ~PointerControllerTest(); @@ -173,26 +183,16 @@ protected: std::unique_ptr<MockSpriteController> mSpriteController; std::shared_ptr<PointerController> mPointerController; sp<android::gui::WindowInfosListener> mRegisteredListener; + sp<MyLooper> mLooper; private: - void loopThread(); - - std::atomic<bool> mRunning = true; - class MyLooper : public Looper { - public: - MyLooper() : Looper(false) {} - ~MyLooper() = default; - }; std::thread mThread; - -protected: - sp<MyLooper> mLooper; }; PointerControllerTest::PointerControllerTest() : mPointerSprite(new NiceMock<MockSprite>), - mThread(&PointerControllerTest::loopThread, this), - mLooper(new MyLooper) { + mLooper(new MyLooper), + mThread(&PointerControllerTest::loopThread, this) { mSpriteController.reset(new NiceMock<MockSpriteController>(mLooper)); mPolicy = new MockPointerControllerPolicyInterface(); |