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

Commit 0c7e0b3e authored by William Escande's avatar William Escande
Browse files

Ensure future are reset before being set

This avoid async flakiness when test assert the future is null before
enqueue next packet

Test: atest --host
Bug: 264572812
Change-Id: Iac9e2f0722db5d6d4c148358d96bb1df1f00aebf
parent 5182c686
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -124,8 +124,9 @@ class TestAclConnectionInterface : public hci::AclConnectionInterface {
    command_queue_.push(std::move(command));
    command_status_callbacks.push_back(std::move(on_status));
    if (command_promise_ != nullptr) {
      command_promise_->set_value();
      command_promise_.reset();
      std::promise<void>* prom = command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

@@ -136,8 +137,9 @@ class TestAclConnectionInterface : public hci::AclConnectionInterface {
    command_queue_.push(std::move(command));
    command_complete_callbacks.push_back(std::move(on_complete));
    if (command_promise_ != nullptr) {
      command_promise_->set_value();
      command_promise_.reset();
      std::promise<void>* prom = command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

+6 −4
Original line number Diff line number Diff line
@@ -102,8 +102,9 @@ class TestLeAclConnectionInterface : public hci::LeAclConnectionInterface {
    command_queue_.push(std::move(command));
    command_status_callbacks.push_back(std::move(on_status));
    if (command_promise_ != nullptr) {
      command_promise_->set_value();
      command_promise_.reset();
      std::promise<void>* prom = command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

@@ -114,8 +115,9 @@ class TestLeAclConnectionInterface : public hci::LeAclConnectionInterface {
    command_queue_.push(std::move(command));
    command_complete_callbacks.push_back(std::move(on_complete));
    if (command_promise_ != nullptr) {
      command_promise_->set_value();
      command_promise_.reset();
      std::promise<void>* prom = command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

+6 −4
Original line number Diff line number Diff line
@@ -256,8 +256,9 @@ class TestHciLayer : public HciLayer {
    command_queue_.push(std::move(command));
    command_status_callbacks.push_back(std::move(on_status));
    if (command_promise_ != nullptr) {
      command_promise_->set_value();
      command_promise_.reset();
      std::promise<void>* prom = command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

@@ -268,8 +269,9 @@ class TestHciLayer : public HciLayer {
    command_queue_.push(std::move(command));
    command_complete_callbacks.push_back(std::move(on_complete));
    if (command_promise_ != nullptr) {
      command_promise_->set_value();
      command_promise_.reset();
      std::promise<void>* prom = command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

+6 −4
Original line number Diff line number Diff line
@@ -320,8 +320,9 @@ class TestHciLayer : public HciLayer {
 private:
  void Notify() {
    if (hci_command_promise_ != nullptr) {
      hci_command_promise_->set_value();
      hci_command_promise_.reset();
      std::promise<void>* prom = hci_command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

@@ -372,8 +373,9 @@ class MockLeConnectionCallbacks : public LeConnectionCallbacks {
  void OnLeConnectSuccess(AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) override {
    le_connections_.push_back(std::move(connection));
    if (le_connection_promise_ != nullptr) {
      le_connection_promise_->set_value();
      le_connection_promise_.reset();
      std::promise<void>* prom = le_connection_promise_.release();
      prom->set_value();
      delete prom;
    }
  }
  MOCK_METHOD(void, OnLeConnectFail, (AddressWithType, ErrorCode reason, bool locally_initiated), (override));
+9 −9
Original line number Diff line number Diff line
@@ -84,18 +84,18 @@ class TestHciHal : public hal::HciHal {
  void sendHciCommand(hal::HciPacket command) override {
    outgoing_commands_.push_back(std::move(command));
    if (sent_command_promise_ != nullptr) {
      auto promise = std::move(sent_command_promise_);
      sent_command_promise_.reset();
      promise->set_value();
      std::promise<void>* prom = sent_command_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

  void sendAclData(hal::HciPacket data) override {
    outgoing_acl_.push_back(std::move(data));
    if (sent_acl_promise_ != nullptr) {
      auto promise = std::move(sent_acl_promise_);
      sent_acl_promise_.reset();
      promise->set_value();
      std::promise<void>* prom = sent_acl_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

@@ -106,9 +106,9 @@ class TestHciHal : public hal::HciHal {
  void sendIsoData(hal::HciPacket data) override {
    outgoing_iso_.push_back(std::move(data));
    if (sent_iso_promise_ != nullptr) {
      auto promise = std::move(sent_iso_promise_);
      sent_iso_promise_.reset();
      promise->set_value();
      std::promise<void>* prom = sent_iso_promise_.release();
      prom->set_value();
      delete prom;
    }
  }

Loading