Repository: denoland/deno
File: tests/integration/mod.rs (Rust)

Code before:
    CollectedTestCategory {
      name: module_path!().to_string(),
      path: PathBuf::from(file!()),
      children: Default::default(),
    };
  test_util::collect_and_filter_tests(&mut main_category);
  if main_category.is_empty() {
    return; // no tests to run for the filter
  }

  let run_test = move |test: &CollectedTest<&'static TestMacroCase>,
                       parallelism: Option<&Parallelism>| {
    if test.data.ignore {
      return TestResult::Ignored;
    }
    let run_test = || {
      let _test_timeout_holder = test.data.timeout.map(|timeout_secs| {
        test_util::test_runner::with_timeout(
          test.name.clone(),
          std::time::Duration::from_secs(timeout_secs as u64),
        )
      });
      let (mut captured_output, result) =
        test_util::print::with_captured_output(|| {
          TestResult::from_maybe_panic_or_result(AssertUnwindSafe(|| {
            (test.data.func)();
            TestResult::Passed { duration: None }
          }))
        });
      match result {
        TestResult::Passed { .. } | TestResult::Ignored => result,
        TestResult::Failed { output, duration } => {
          if !captured_output.is_empty() {
            captured_output.push(b'\n');
          }
          captured_output.extend_from_slice(&output);
          TestResult::Failed {
            duration,
            output: captured_output,
          }
        }
        // no support for sub tests
        TestResult::SubTests { .. } => unreachable!(),
      }
    };
    if test.data.flaky {
      run_flaky_test(&test.name, parallelism, run_test)
    } else {
      flaky_test_ci(&test.name, parallelism, run_test)
    }
  };

Review comment (suggestion):
The duration can now be optionally reported on the TestResult instead of using file_test_runner's built-in duration reporting. This is useful for us here because when a test is super flaky we back a lot of them up to cause the flaky test to run in isolation.

Code after:
      name: module_path!().to_string(),
      path: PathBuf::from(file!()),
      children: Default::default(),
    };
  test_util::collect_and_filter_tests(&mut main_category);
  if main_category.is_empty() {
    return; // no tests to run for the filter
  }

  let run_test = move |test: &CollectedTest<&'static TestMacroCase>,
                       parallelism: Option<&Parallelism>| {
    if test.data.ignore {
      return TestResult::Ignored;
    }
    let run_test = || {
      let _test_timeout_holder = test.data.timeout.map(|timeout_secs| {
        test_util::test_runner::with_timeout(
          test.name.clone(),
          std::time::Duration::from_secs(timeout_secs as u64),
        )
      });
      let (mut captured_output, result) =
        test_util::print::with_captured_output(|| {
          TestResult::from_maybe_panic_or_result(AssertUnwindSafe(|| {
            (test.data.func)();
            TestResult::Passed { duration: None }
          }))
        });
      match result {
        TestResult::Passed { .. } | TestResult::Ignored => result,
        TestResult::Failed { output, duration } => {
          if !captured_output.is_empty() {
            captured_output.push(b'\n');
          }
          captured_output.extend_from_slice(&output);
          TestResult::Failed {
            duration,
            output: captured_output,
          }
        }
        // no support for sub tests
        TestResult::SubTests { .. } => unreachable!(),
      }
    };
    run_maybe_flaky_test(
      &test.name,
      test.data.flaky || *test_util::IS_CI,
      parallelism,
      run_test,
    )
  };