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

Commit 0a6c76b6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "BluetoothMetrics: Fix LRU eviction callback bug" into rvc-dev am: ec760eed

Change-Id: I52f995964b0004cc643ffef98fa66fc2cb4d20d0
parents 1e606c1b ec760eed
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -119,8 +119,10 @@ class LruCache {
    // remove tail
    if (lru_map_.size() == capacity_) {
      lru_map_.erase(node_list_.back().first);
      K key_evicted = node_list_.back().first;
      V value_evicted = node_list_.back().second;
      node_list_.pop_back();
      lru_eviction_callback_(node_list_.back().first, node_list_.back().second);
      lru_eviction_callback_(key_evicted, value_evicted);
      value_popped = true;
    }
    // insert to dummy next;
+5 −4
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) {
  int* value = new int(0);
  int dummy = 0;
  int* pointer = &dummy;
  auto callback = [pointer](int a, int b) { (*pointer) = 1; };
  auto callback = [pointer](int a, int b) { (*pointer) = a * b; };
  LruCache<int, int> cache(3, "testing", callback);  // capacity = 3;
  cache.Put(1, 10);
  EXPECT_EQ(cache.Size(), 1);
@@ -51,8 +51,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) {
  EXPECT_EQ(cache.Size(), 3);

  cache.Put(4, 40);
  EXPECT_EQ(dummy, 1);
  // 2, 3, 4 should be in cache, 1 should not
  EXPECT_EQ(dummy, 10);
  // 2, 3, 4 should be in cache, 1 is evicted
  EXPECT_FALSE(cache.Get(1, value));
  EXPECT_TRUE(cache.Get(4, value));
  EXPECT_EQ(*value, 40);
@@ -63,7 +63,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) {

  cache.Put(5, 50);
  EXPECT_EQ(cache.Size(), 3);
  // 2, 3, 5 should be in cache
  EXPECT_EQ(dummy, 160);
  // 2, 3, 5 should be in cache, 4 is evicted

  EXPECT_TRUE(cache.Remove(3));
  cache.Put(6, 60);