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

Commit 84e3cb66 authored by Myles Watson's avatar Myles Watson
Browse files

RootCanal: Use CancelAsyncTask in test_environment

Swap two callbacks in test_environment.h
Clean up the list of tasks when cancelled for a user.

Bug: 154020729
Test: cert/run --host
Tag: #stability
Change-Id: I9607c58f4db13b32e2dbbf88dd88d522c6c031b9
parent 4a25208c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -71,14 +71,14 @@ class TestEnvironment {
                                                    task);
      },

      [this](test_vendor_lib::AsyncTaskId task) {
        async_manager_.CancelAsyncTask(task);
      },

      [this](test_vendor_lib::AsyncUserId user) {
        async_manager_.CancelAsyncTasksFromUser(user);
      },

      [this](test_vendor_lib::AsyncTaskId task) {
        async_manager_.CancelAsyncTask(task);
      },

      [this](const std::string& server, int port) {
        return ConnectToRemoteServer(server, port);
      }};
+12 −9
Original line number Diff line number Diff line
@@ -287,12 +287,7 @@ class AsyncManager::AsyncTaskManager {
  bool CancelAsyncTask(AsyncTaskId async_task_id) {
    // remove task from queue (and task id association) while holding lock
    std::unique_lock<std::mutex> guard(internal_mutex_);
    if (tasks_by_id_.count(async_task_id) == 0) {
      return false;
    }
    task_queue_.erase(tasks_by_id_[async_task_id]);
    tasks_by_id_.erase(async_task_id);
    return true;
    return cancel_task_with_lock_held(async_task_id);
  }

  bool CancelAsyncTasksFromUser(AsyncUserId user_id) {
@@ -302,10 +297,9 @@ class AsyncManager::AsyncTaskManager {
      return false;
    }
    for (auto task : tasks_by_user_id_[user_id]) {
      if (tasks_by_id_.count(task) != 0) {
        tasks_by_id_.erase(task);
      }
      cancel_task_with_lock_held(task);
    }
    tasks_by_user_id_.erase(user_id);
    return true;
  }

@@ -382,6 +376,15 @@ class AsyncManager::AsyncTaskManager {
    }
  };

  bool cancel_task_with_lock_held(AsyncTaskId async_task_id) {
    if (tasks_by_id_.count(async_task_id) == 0) {
      return false;
    }
    task_queue_.erase(tasks_by_id_[async_task_id]);
    tasks_by_id_.erase(async_task_id);
    return true;
  }

  AsyncTaskId scheduleTask(const std::shared_ptr<Task>& task) {
    {
      std::unique_lock<std::mutex> guard(internal_mutex_);