diff --git a/src/session/Manager.cc b/src/session/Manager.cc index 1792a212ed..6fdf275004 100644 --- a/src/session/Manager.cc +++ b/src/session/Manager.cc @@ -218,19 +218,34 @@ void Manager::Insert(Session* s, bool remove_existing) void Manager::Drain() { - std::vector keys; - keys.reserve(session_map.size()); - - 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 ) + // If a random seed was passed in, we're most likely in testing mode and need the + // order of the sessions to be consistent. Sort the keys to force that order + // every run. + if ( zeek::util::detail::have_random_seed() ) { - Session* tc = session_map.at(*k); - tc->Done(); - tc->RemovalEvent(); + std::vector keys; + keys.reserve(session_map.size()); + + 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(); + } } }