Skip to content

Commit

Permalink
Wait until fair queue source drains before removal (#4597)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev authored May 3, 2024
1 parent 04de36c commit 3dc70af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions nano/core_test/fair_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,20 @@ TEST (fair_queue, cleanup)
ASSERT_EQ (queue.size ({ source_enum::live, channel2 }), 1);
ASSERT_EQ (queue.size ({ source_enum::live, channel3 }), 1);

// Either closing or resetting the channel should remove it from the queue
// Either closing or resetting the channel should make it eligible for cleanup
channel1->close ();
channel2.reset ();

ASSERT_TRUE (queue.periodic_update ());
ASSERT_TRUE (queue.periodic_update (0s));

// Only channel 3 should remain
ASSERT_EQ (queue.size (), 1);
ASSERT_EQ (queue.queues_size (), 1);
// Until the queue is drained, the entries are still present
ASSERT_EQ (queue.size (), 3);
ASSERT_EQ (queue.queues_size (), 3);

ASSERT_EQ (queue.size ({ source_enum::live, channel1 }), 0);
ASSERT_EQ (queue.size ({ source_enum::live, channel2 }), 0);
ASSERT_EQ (queue.size ({ source_enum::live, channel3 }), 1);
queue.next_batch (999);

ASSERT_TRUE (queue.periodic_update (0s));

ASSERT_TRUE (queue.empty ());
ASSERT_EQ (queue.queues_size (), 1);
}
2 changes: 1 addition & 1 deletion nano/node/fair_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class fair_queue final
iterator = queues.end ();

erase_if (queues, [] (auto const & entry) {
return !entry.first.alive ();
return entry.second.empty () && !entry.first.alive ();
});
}

Expand Down

0 comments on commit 3dc70af

Please sign in to comment.