@@ -2523,27 +2523,22 @@ fn assert_tracker_noexistence(key: &str) {
2523
2523
#[ cargo_test]
2524
2524
fn uninstall_running_binary ( ) {
2525
2525
Package :: new ( "foo" , "0.0.1" )
2526
- . file ( "src/lib.rs" , "" )
2527
2526
. file (
2528
2527
"Cargo.toml" ,
2529
2528
r#"
2530
- [package]
2531
- name = "foo"
2532
- version = "0.0.1"
2533
-
2534
- [[bin]]
2535
- name = "foo"
2536
- path = "src/main.rs"
2537
- "# ,
2529
+ [package]
2530
+ name = "foo"
2531
+ version = "0.0.1"
2532
+ "# ,
2538
2533
)
2539
2534
. file (
2540
2535
"src/main.rs" ,
2541
2536
r#"
2542
- use std::{{thread, time}};
2543
- fn main() {
2544
- thread::sleep(time::Duration::from_secs(3) );
2545
- }
2546
- "# ,
2537
+ fn main() {
2538
+ std::net::TcpStream::connect(&std::env::var("ADDR").unwrap()[..]).unwrap();
2539
+ std::net::TcpStream::connect(&std::env::var("ADDR").unwrap()[..]).unwrap( );
2540
+ }
2541
+ "#,
2547
2542
)
2548
2543
. publish ( ) ;
2549
2544
@@ -2565,15 +2560,26 @@ fn uninstall_running_binary() {
2565
2560
assert_has_installed_exe ( cargo_home ( ) , "foo" ) ;
2566
2561
2567
2562
let foo_bin = cargo_home ( ) . join ( "bin" ) . join ( exe ( "foo" ) ) ;
2568
- let t = thread:: spawn ( || ProcessBuilder :: new ( foo_bin) . exec ( ) . unwrap ( ) ) ;
2563
+ let l = std:: net:: TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
2564
+ let addr = l. local_addr ( ) . unwrap ( ) . to_string ( ) ;
2565
+ let t = thread:: spawn ( move || {
2566
+ ProcessBuilder :: new ( foo_bin)
2567
+ . env ( "ADDR" , addr)
2568
+ . exec ( )
2569
+ . unwrap ( ) ;
2570
+ } ) ;
2569
2571
let key = "foo 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" ;
2570
2572
2571
2573
#[ cfg( windows) ]
2572
2574
{
2575
+ // Ensure foo is running before the first `cargo uninstall` call
2576
+ l. accept ( ) . unwrap ( ) ;
2573
2577
cargo_process ( "uninstall foo" )
2574
2578
. with_status ( 101 )
2575
2579
. with_stderr_contains ( "[ERROR] failed to remove file `[CWD]/home/.cargo/bin/foo[EXE]`" )
2576
2580
. run ( ) ;
2581
+ // Ensure foo is stopped before the second `cargo uninstall` call
2582
+ l. accept ( ) . unwrap ( ) ;
2577
2583
t. join ( ) . unwrap ( ) ;
2578
2584
cargo_process ( "uninstall foo" )
2579
2585
. with_stderr ( "[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]" )
@@ -2582,9 +2588,13 @@ fn uninstall_running_binary() {
2582
2588
2583
2589
#[ cfg( not( windows) ) ]
2584
2590
{
2591
+ // Ensure foo is running before the first `cargo uninstall` call
2592
+ l. accept ( ) . unwrap ( ) ;
2585
2593
cargo_process ( "uninstall foo" )
2586
2594
. with_stderr ( "[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]" )
2587
2595
. run ( ) ;
2596
+ // Ensure foo is stopped before the second `cargo uninstall` call
2597
+ l. accept ( ) . unwrap ( ) ;
2588
2598
t. join ( ) . unwrap ( ) ;
2589
2599
} ;
2590
2600
0 commit comments