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
This commit is contained in:
parent
a682b181d9
commit
705297317b
3 changed files with 18 additions and 1 deletions
|
@ -44,6 +44,10 @@ void ThreadController::stop() {
|
|||
mWorkerStateChangeRequest = true;
|
||||
}
|
||||
}
|
||||
join();
|
||||
}
|
||||
|
||||
void ThreadController::join() {
|
||||
if (mWorker.joinable()) {
|
||||
mWorker.join();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue