Only sort sessions during Drain() if a random seed is set

This commit is contained in:
Tim Wojtulewicz 2021-08-03 10:07:47 -07:00
parent e2dc6df8a2
commit 201617540d

View file

@ -218,19 +218,34 @@ void Manager::Insert(Session* s, bool remove_existing)
void Manager::Drain() void Manager::Drain()
{ {
std::vector<const detail::Key*> keys; // If a random seed was passed in, we're most likely in testing mode and need the
keys.reserve(session_map.size()); // order of the sessions to be consistent. Sort the keys to force that order
// every run.
for ( auto& entry : session_map ) if ( zeek::util::detail::have_random_seed() )
keys.push_back(&(entry.first));
std::sort(keys.begin(), keys.end(), [](const detail::Key* a, const detail::Key* b) {
return *a < *b; });
for ( const auto* k : keys )
{ {
Session* tc = session_map.at(*k); std::vector<const detail::Key*> keys;
tc->Done(); keys.reserve(session_map.size());
tc->RemovalEvent();
for ( auto& entry : session_map )
keys.push_back(&(entry.first));
std::sort(keys.begin(), keys.end(), [](const detail::Key* a, const detail::Key* b) {
return *a < *b; });
for ( const auto* k : keys )
{
Session* tc = session_map.at(*k);
tc->Done();
tc->RemovalEvent();
}
}
else
{
for ( const auto& entry : session_map )
{
Session* tc = entry.second;
tc->Done();
tc->RemovalEvent();
}
} }
} }