Skip to content

Commit

Permalink
Update some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilsnd committed May 17, 2024
1 parent 2a720ef commit 1aaf423
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/actor/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Scheduler {

/// Wait until there's nothing pending or in process
/// Must not be called from a task provided to this scheduler.
virtual void waitForEmpty(const void*) = 0;
virtual void waitForEmpty(const void* tag = nullptr) = 0;

/// Set/Get the current Scheduler for this thread
static Scheduler* GetCurrent();
Expand Down
8 changes: 6 additions & 2 deletions test/actor/actor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ TEST(Actor, DestructionBlocksOnSend) {

~TestScheduler() override { EXPECT_TRUE(waited.load()); }

std::size_t waitForEmpty(Milliseconds) override {
void waitForEmpty(const void*) override {
assert(false);
return 0;
}

void schedule(std::function<void()>&&) final {
Expand All @@ -102,6 +101,11 @@ TEST(Actor, DestructionBlocksOnSend) {
std::this_thread::sleep_for(1ms);
waited = true;
}

void schedule(const void*, std::function<void()>&& fn) final {
schedule(std::move(fn));
}

mapbox::base::WeakPtr<Scheduler> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
};

Expand Down
4 changes: 2 additions & 2 deletions test/include/mbgl/test/vector_tile_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class VectorTileTest {

~VectorTileTest() {
// Ensure that deferred releases are complete before cleaning up
EXPECT_EQ(0, loop.waitForEmpty(Milliseconds::zero()));
EXPECT_EQ(0, threadPool->waitForEmpty());
loop.waitForEmpty();
threadPool->waitForEmpty();
}
};

Expand Down
29 changes: 7 additions & 22 deletions test/util/thread.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ TEST(Thread, PoolWait) {
pool->schedule([&] { std::this_thread::sleep_for(Milliseconds(100)); });
}

EXPECT_EQ(0, pool->waitForEmpty());
pool->waitForEmpty();
}

TEST(Thread, PoolWaitRecursiveAdd) {
Expand All @@ -358,7 +358,7 @@ TEST(Thread, PoolWaitRecursiveAdd) {
std::this_thread::sleep_for(Milliseconds(10));
});

EXPECT_EQ(0, pool->waitForEmpty());
pool->waitForEmpty();
}

TEST(Thread, PoolWaitAdd) {
Expand All @@ -385,25 +385,10 @@ TEST(Thread, PoolWaitAdd) {
// more items would be added by the sequential task if not blocked
pool->schedule([&] { std::this_thread::sleep_for(Milliseconds(100)); });

EXPECT_EQ(0, pool->waitForEmpty());
pool->waitForEmpty();

addActive = false;
EXPECT_EQ(0, pool->waitForEmpty());
}

TEST(Thread, PoolWaitTimeout) {
auto pool = Scheduler::GetBackground();

std::mutex mutex;
{
std::lock_guard<std::mutex> outerLock(mutex);
pool->schedule([&] { std::lock_guard<std::mutex> innerLock(mutex); });

// should always time out
EXPECT_EQ(1, pool->waitForEmpty(Milliseconds(100)));
}

EXPECT_EQ(0, pool->waitForEmpty());
pool->waitForEmpty();
}

TEST(Thread, PoolWaitException) {
Expand All @@ -425,7 +410,7 @@ TEST(Thread, PoolWaitException) {
}

// Exceptions shouldn't cause deadlocks by, e.g., abandoning locks.
EXPECT_EQ(0, pool->waitForEmpty());
pool->waitForEmpty();
EXPECT_EQ(threadCount, caught);
}

Expand All @@ -434,8 +419,8 @@ TEST(Thread, WrongThread) {
auto pool = Scheduler::GetBackground();

// Asserts in debug builds, silently ignored in release.
pool->schedule([&] { EXPECT_EQ(0, pool->waitForEmpty()); });
pool->schedule([&] { pool->waitForEmpty(); });

EXPECT_EQ(0, pool->waitForEmpty());
pool->waitForEmpty();
}
#endif

0 comments on commit 1aaf423

Please sign in to comment.