2020//! file, so the worktree stays clean.
2121
2222use std:: path:: { Path , PathBuf } ;
23+ use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
2324
2425use codegraph_core:: types:: { Edge , EdgeKind , FileRecord , Node , NodeKind } ;
2526use codegraph_extract:: { detect_language, extract_file} ;
2627use codegraph_resolve:: ReferenceResolver ;
2728use codegraph_store:: Store ;
2829
30+ static NEXT_TEMP_DB : AtomicU64 = AtomicU64 :: new ( 0 ) ;
31+
2932fn fixture_root ( name : & str ) -> PathBuf {
3033 Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
3134 . join ( "tests" )
@@ -35,18 +38,34 @@ fn fixture_root(name: &str) -> PathBuf {
3538}
3639
3740fn temp_db_path ( test_name : & str ) -> PathBuf {
38- let mut path = std:: env:: temp_dir ( ) ;
3941 let nanos = std:: time:: SystemTime :: now ( )
4042 . duration_since ( std:: time:: UNIX_EPOCH )
4143 . expect ( "clock after epoch" )
4244 . as_nanos ( ) ;
45+ temp_db_path_at ( test_name, nanos)
46+ }
47+
48+ fn temp_db_path_at ( test_name : & str , nanos : u128 ) -> PathBuf {
49+ let mut path = std:: env:: temp_dir ( ) ;
50+ // Windows may return the same wall-clock value to parallel tests. The
51+ // process-local nonce keeps same-fixture stores collision-free regardless
52+ // of clock resolution.
53+ let nonce = NEXT_TEMP_DB . fetch_add ( 1 , Ordering :: Relaxed ) ;
4354 path. push ( format ! (
44- "codegraph-tier6-{test_name}-{}-{nanos}.db" ,
55+ "codegraph-tier6-{test_name}-{}-{nanos}-{nonce} .db" ,
4556 std:: process:: id( )
4657 ) ) ;
4758 path
4859}
4960
61+ #[ test]
62+ fn temp_db_paths_remain_unique_when_clock_does_not_advance ( ) {
63+ assert_ne ! (
64+ temp_db_path_at( "same_fixture" , 42 ) ,
65+ temp_db_path_at( "same_fixture" , 42 )
66+ ) ;
67+ }
68+
5069/// Every indexable file under `root`, as project-relative `/`-separated paths,
5170/// sorted so indexing order is deterministic.
5271fn fixture_files ( root : & Path ) -> Vec < String > {
0 commit comments