Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Thanks Aaron.
  • Loading branch information
matanlurey committed Sep 7, 2023
commit 82fb32c271f77e339e86b0f7b18d196331a302ea
23 changes: 10 additions & 13 deletions impeller/renderer/backend/vulkan/resource_manager_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <functional>
#include <memory>
#include <utility>
#include "fml/synchronization/waitable_event.h"
#include "gtest/gtest.h"
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"

Expand All @@ -19,6 +20,8 @@ TEST(ResourceManagerVKTest, CreatesANewInstance) {
EXPECT_NE(a, b);
}

namespace {

// Invokes the provided callback when the destructor is called.
//
// Can be moved, but not copied.
Expand All @@ -36,32 +39,26 @@ class DeathRattle final {
std::function<void()> callback_;
};

} // namespace

TEST(ResourceManagerVKTest, ReclaimMovesAResourceAndDestroysIt) {
auto const manager = ResourceManagerVK::Create();

auto waiter = fml::AutoResetWaitableEvent();
auto dead = false;
auto rattle = DeathRattle([&dead]() { dead = true; });
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });

// Not killed immediately.
EXPECT_FALSE(dead);
EXPECT_FALSE(waiter.IsSignaledForTest());

{
auto resource = UniqueResourceVKT<DeathRattle>(manager, std::move(rattle));

// Not killed on moving.
EXPECT_FALSE(dead);
}

// Not killed synchronously.
EXPECT_FALSE(dead);

// A background thread reclaims; give it a chance to finish killing.
while (!dead) {
std::this_thread::yield();
EXPECT_FALSE(waiter.IsSignaledForTest());
}

// The resource should be dead now.
EXPECT_TRUE(dead);
waiter.Wait();
}

} // namespace testing
Expand Down