Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2c839d2 authored by Arpit Singh's avatar Arpit Singh
Browse files

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
parent e89f7097
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -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();