@@ -323,6 +323,44 @@ mod tests {
323323 ) ;
324324 }
325325
326+ /// Throwaway probe two: does manual removal also work while another HANDLE
327+ /// (share-delete) is still open, as a retained memmap2 handle would be?
328+ #[ cfg( windows) ]
329+ #[ test]
330+ fn probe_manual_delete_with_open_handle ( ) {
331+ let path = std:: path:: absolute ( temp_dir ( ) )
332+ . unwrap ( )
333+ . join ( format ! ( "{BACKING_PREFIX}probe2-{}.shm" , Uuid :: new_v4( ) . simple( ) ) ) ;
334+ let mut options = OpenOptions :: new ( ) ;
335+ options. read ( true ) . write ( true ) . create_new ( true ) ;
336+ {
337+ use std:: os:: windows:: fs:: OpenOptionsExt as _;
338+ options. share_mode ( sys:: SHARE_ALL ) . attributes ( sys:: TEMPORARY ) ;
339+ }
340+ let file = options. open ( & path) . unwrap ( ) ;
341+ sys:: set_sparse ( & file) . unwrap ( ) ;
342+ file. set_len ( 65536 ) . unwrap ( ) ;
343+ let mapping = map ( & file, 65536 ) . unwrap ( ) ;
344+ // Keep `file` open: it stands in for the handle memmap2 would retain.
345+ // SAFETY: in bounds, no concurrent access.
346+ unsafe { mapping. as_ptr ( ) . write ( 17 ) } ;
347+
348+ let removed = fs:: remove_file ( & path) ;
349+ let exists_after = path. exists ( ) ;
350+ let reopen_fails = OpenOptions :: new ( ) . read ( true ) . open ( & path) . is_err ( ) ;
351+ // SAFETY: in bounds, no concurrent access.
352+ let view_alive = unsafe { mapping. as_ptr ( ) . read ( ) } == 17 ;
353+ let handle_still_writes = {
354+ use std:: io:: Write as _;
355+ ( & file) . write_all ( b"x" ) . is_ok ( )
356+ } ;
357+ panic ! (
358+ "PROBE2 remove_file={removed:?} exists_after={exists_after} \
359+ reopen_fails={reopen_fails} view_alive={view_alive} \
360+ handle_still_writes={handle_still_writes}"
361+ ) ;
362+ }
363+
326364 #[ test]
327365 fn subprocess_open_ignores_changed_temp_and_working_directory ( ) {
328366 let keeper = create ( SIZE ) . unwrap ( ) ;
0 commit comments