@@ -181,7 +181,6 @@ struct TraceTestCase {
181181// Table-programming helpers: perform the operation and print one line
182182// describing it. Errors are printed to stdout so that they break the golden
183183// diff instead of going unnoticed.
184-
185184void set_default_action (SimpleSwitch* sw, std::ostream& os,
186185 const std::string& table, const std::string& action,
187186 const std::vector<unsigned >& args = {}) {
@@ -251,29 +250,19 @@ std::map<std::string, std::string> read_traces(const fs::path& dir) {
251250}
252251
253252// Traces are flushed when the switch destroys a packet, which happens shortly
254- // *after* the corresponding output packet (if any) is transmitted, and a
255- // single input may produce several traces (e.g. recirculation). So rather
256- // than waiting for an expected file count, wait for the trace directory to
257- // quiesce: at least min_expected parseable files, unchanged for a settle
258- // period .
253+ // *after* the corresponding output packet (if any) is transmitted, so the
254+ // trace files may not exist yet when the output packets have all been
255+ // collected. Each input packet produces exactly one trace file (clones and
256+ // recirculated copies attach to the same recursive trace), so poll until
257+ // `expected` files parse or the timeout expires .
259258std::map<std::string, std::string> wait_for_traces (const fs::path& dir,
260- size_t min_expected ) {
259+ size_t expected ) {
261260 using clock = std::chrono::steady_clock;
262- constexpr auto kSettleTime = std::chrono::milliseconds (300 );
263- constexpr auto kTimeout = std::chrono::seconds (5 );
264- const auto deadline = clock::now () + kTimeout ;
261+ const auto deadline = clock::now () + std::chrono::seconds (5 );
265262 auto traces = read_traces (dir);
266- auto last_change = clock::now ();
267- while (clock::now () < deadline) {
263+ while (traces.size () < expected && clock::now () < deadline) {
268264 std::this_thread::sleep_for (std::chrono::milliseconds (25 ));
269- auto current = read_traces (dir);
270- if (current != traces) {
271- traces = std::move (current);
272- last_change = clock::now ();
273- } else if (traces.size () >= min_expected &&
274- clock::now () - last_change >= kSettleTime ) {
275- break ;
276- }
265+ traces = read_traces (dir);
277266 }
278267 return traces;
279268}
0 commit comments