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

Commit 70529731 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Add 'join' method to StreamWorker

This is intended for use in tests where the worker
just executes some actions and then exits by itself.
Use of 'join' instead of 'stop' ensures that the
worker goes through all actions.

Bug: 205884982
Test: atest libaudioaidlcommon_test
Change-Id: I8a9f4f0bb786ee606e3b63a9847f414119716a7d
parent a682b181
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ void ThreadController::stop() {
            mWorkerStateChangeRequest = true;
        }
    }
    join();
}

void ThreadController::join() {
    if (mWorker.joinable()) {
        mWorker.join();
    }
+6 −1
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ class ThreadController {
        return mError;
    }
    void stop();
    // Direct use of 'join' assumes that the StreamLogic is not intended
    // to run forever, and is guaranteed to exit by itself. This normally
    // only happen in tests.
    void join();
    bool waitForAtLeastOneCycle();

    // Only used by unit tests.
@@ -133,7 +137,8 @@ class StreamWorker : public LogicImpl {
    void resume() { mThread.resume(); }
    bool hasError() { return mThread.hasError(); }
    std::string getError() { return mThread.getError(); }
    void stop() { return mThread.stop(); }
    void stop() { mThread.stop(); }
    void join() { mThread.join(); }
    bool waitForAtLeastOneCycle() { return mThread.waitForAtLeastOneCycle(); }

    // Only used by unit tests.
+8 −0
Original line number Diff line number Diff line
@@ -160,6 +160,14 @@ TEST_P(StreamWorkerTest, WorkerExit) {
    EXPECT_TRUE(worker.hasNoWorkerCycleCalled(kWorkerIdleCheckTime));
}

TEST_P(StreamWorkerTest, WorkerJoin) {
    ASSERT_TRUE(worker.start());
    stream.setStopStatus();
    worker.join();
    EXPECT_FALSE(worker.hasError());
    EXPECT_TRUE(worker.hasNoWorkerCycleCalled(kWorkerIdleCheckTime));
}

TEST_P(StreamWorkerTest, WorkerError) {
    ASSERT_TRUE(worker.start());
    stream.setErrorStatus();