MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / test_single_long_execution

Function test_single_long_execution

crates/exec-harness/src/walltime/tests.rs:263–303  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

261/// Test that when a warmup run exceeds max_time, the command is only run once
262#[test]
263fn test_single_long_execution() -> Result<()> {
264 // Set max_time very low and warmup time high to force single execution
265 let exec_opts = ExecutionOptions::try_from(WalltimeExecutionArgs {
266 warmup_time: Some("100ms".to_string()),
267 max_time: Some("100ms".to_string()), // Low max time, shorter than command duration
268 min_time: None,
269 max_rounds: None,
270 min_rounds: None,
271 })?;
272
273 // Create a temporary directory for the test
274 let tmpdir = TempDir::new()?;
275
276 // Create a command that sleeps and creates a directory that must not exist
277 // This will fail if executed twice because the directory will already exist
278 let test_dir = tmpdir.path().join("lock_file");
279 let cmd = format!("sleep 1 && mkdir {}", test_dir.display());
280
281 let times = run_rounds(
282 "test::single_long_execution".to_string(),
283 vec!["sh".to_string(), "-c".to_string(), cmd.clone()],
284 &exec_opts,
285 )?;
286
287 // Should have run exactly once
288 assert_eq!(times.len(), 1, "Expected exactly one iteration");
289
290 // Sanity check: any subsequent run should fail due to directory existing, to avoid false
291 // positives
292 assert!(
293 run_rounds(
294 "test::single_long_execution".to_string(),
295 vec!["sh".to_string(), "-c".to_string(), cmd],
296 &exec_opts,
297 )
298 .is_err(),
299 "Expected failure on second execution due to existing directory"
300 );
301
302 Ok(())
303}
304
305/// Test that a command with shell operators (&&) works correctly when passed as a single argument
306#[test]

Callers

nothing calls this directly

Calls 2

run_roundsFunction · 0.85
pathMethod · 0.80

Tested by

no test coverage detected