Skip to content

Commit 4d7c0e5

Browse files
committed
Migrate self update tests to parallel execution
Drops us down to 45 seconds total execution time for me.
1 parent 15157b7 commit 4d7c0e5

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

tests/cli-self-upd.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn setup(f: &dyn Fn(&Config)) {
4444
}
4545

4646
pub fn update_setup(f: &dyn Fn(&Config, &Path)) {
47-
setup(&|config| {
47+
clitools::setup(Scenario::SimpleV2, &|config| {
4848
// Create a mock self-update server
4949
let self_dist_tmp = tempfile::Builder::new()
5050
.prefix("self_dist")
@@ -64,7 +64,7 @@ pub fn update_setup(f: &dyn Fn(&Config, &Path)) {
6464
raw::append_file(&dist_exe, "").unwrap();
6565

6666
let root_url = format!("file://{}", self_dist.display());
67-
env::set_var("RUSTUP_UPDATE_ROOT", root_url);
67+
config.rustup_update_root = Some(root_url);
6868

6969
f(config, self_dist);
7070
});
@@ -355,7 +355,7 @@ info: downloading self-update
355355
);
356356

357357
update_setup(&|config, _| {
358-
expect_ok(config, &["rustup-init", "-y"]);
358+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
359359
expect_ok_ex(
360360
config,
361361
&["rustup", "self", "update"],
@@ -389,7 +389,7 @@ fn update_but_delete_existing_updater_first() {
389389
.cargodir
390390
.join(&format!("bin/rustup-init{}", EXE_SUFFIX));
391391

392-
expect_ok(config, &["rustup-init", "-y"]);
392+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
393393

394394
// If it happens to already exist for some reason it
395395
// should just be deleted.
@@ -404,7 +404,7 @@ fn update_but_delete_existing_updater_first() {
404404
#[test]
405405
fn update_download_404() {
406406
update_setup(&|config, self_dist| {
407-
expect_ok(config, &["rustup-init", "-y"]);
407+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
408408

409409
let trip = this_host_triple();
410410
let dist_dir = self_dist.join(&format!("archive/{}/{}", TEST_VERSION, trip));
@@ -423,7 +423,7 @@ fn update_download_404() {
423423
#[test]
424424
fn update_bogus_version() {
425425
update_setup(&|config, _| {
426-
expect_ok(config, &["rustup-init", "-y"]);
426+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
427427
expect_err(
428428
config,
429429
&["rustup", "update", "1.0.0-alpha"],
@@ -438,7 +438,7 @@ fn update_bogus_version() {
438438
#[test]
439439
fn update_updates_rustup_bin() {
440440
update_setup(&|config, _| {
441-
expect_ok(config, &["rustup-init", "-y"]);
441+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
442442

443443
let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
444444
let before_hash = calc_hash(&bin);
@@ -464,7 +464,7 @@ fn update_updates_rustup_bin() {
464464
#[test]
465465
fn update_bad_schema() {
466466
update_setup(&|config, self_dist| {
467-
expect_ok(config, &["rustup-init", "-y"]);
467+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
468468
output_release_file(self_dist, "17", "1.1.1");
469469
expect_err(
470470
config,
@@ -478,7 +478,7 @@ fn update_bad_schema() {
478478
fn update_no_change() {
479479
let version = env!("CARGO_PKG_VERSION");
480480
update_setup(&|config, self_dist| {
481-
expect_ok(config, &["rustup-init", "-y"]);
481+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
482482
output_release_file(self_dist, "1", version);
483483
expect_ok_ex(
484484
config,
@@ -496,9 +496,9 @@ fn update_no_change() {
496496
}
497497

498498
#[test]
499-
fn rustup_self_updates() {
499+
fn rustup_self_updates_trivial() {
500500
update_setup(&|config, _| {
501-
expect_ok(config, &["rustup-init", "-y"]);
501+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
502502

503503
let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
504504
let before_hash = calc_hash(&bin);
@@ -514,7 +514,7 @@ fn rustup_self_updates() {
514514
#[test]
515515
fn rustup_self_updates_with_specified_toolchain() {
516516
update_setup(&|config, _| {
517-
expect_ok(config, &["rustup-init", "-y"]);
517+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
518518

519519
let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
520520
let before_hash = calc_hash(&bin);
@@ -530,7 +530,7 @@ fn rustup_self_updates_with_specified_toolchain() {
530530
#[test]
531531
fn rustup_no_self_update_with_specified_toolchain() {
532532
update_setup(&|config, _| {
533-
expect_ok(config, &["rustup-init", "-y"]);
533+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
534534

535535
let bin = config.cargodir.join(&format!("bin/rustup{}", EXE_SUFFIX));
536536
let before_hash = calc_hash(&bin);
@@ -546,7 +546,7 @@ fn rustup_no_self_update_with_specified_toolchain() {
546546
#[test]
547547
fn rustup_self_update_exact() {
548548
update_setup(&|config, _| {
549-
expect_ok(config, &["rustup-init", "-y"]);
549+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
550550

551551
expect_ok_ex(
552552
config,
@@ -574,7 +574,7 @@ info: cleaning up downloads & tmp directories
574574
#[test]
575575
fn updater_leaves_itself_for_later_deletion() {
576576
update_setup(&|config, _| {
577-
expect_ok(config, &["rustup-init", "-y"]);
577+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
578578
expect_ok(config, &["rustup", "update", "nightly"]);
579579
expect_ok(config, &["rustup", "self", "update"]);
580580

@@ -588,7 +588,7 @@ fn updater_leaves_itself_for_later_deletion() {
588588
#[test]
589589
fn updater_is_deleted_after_running_rustup() {
590590
update_setup(&|config, _| {
591-
expect_ok(config, &["rustup-init", "-y"]);
591+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
592592
expect_ok(config, &["rustup", "update", "nightly"]);
593593
expect_ok(config, &["rustup", "self", "update"]);
594594

@@ -604,7 +604,7 @@ fn updater_is_deleted_after_running_rustup() {
604604
#[test]
605605
fn updater_is_deleted_after_running_rustc() {
606606
update_setup(&|config, _| {
607-
expect_ok(config, &["rustup-init", "-y"]);
607+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
608608
expect_ok(config, &["rustup", "default", "nightly"]);
609609
expect_ok(config, &["rustup", "self", "update"]);
610610

@@ -620,7 +620,7 @@ fn updater_is_deleted_after_running_rustc() {
620620
#[test]
621621
fn rustup_still_works_after_update() {
622622
update_setup(&|config, _| {
623-
expect_ok(config, &["rustup-init", "-y"]);
623+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
624624
expect_ok(config, &["rustup", "default", "nightly"]);
625625
expect_ok(config, &["rustup", "self", "update"]);
626626
expect_stdout_ok(config, &["rustc", "--version"], "hash-nightly-2");
@@ -814,7 +814,7 @@ fn rls_proxy_set_up_after_install() {
814814
fn rls_proxy_set_up_after_update() {
815815
update_setup(&|config, _| {
816816
let rls_path = config.cargodir.join(format!("bin/rls{}", EXE_SUFFIX));
817-
expect_ok(config, &["rustup-init", "-y"]);
817+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
818818
fs::remove_file(&rls_path).unwrap();
819819
expect_ok(config, &["rustup", "self", "update"]);
820820
assert!(rls_path.exists());
@@ -824,7 +824,7 @@ fn rls_proxy_set_up_after_update() {
824824
#[test]
825825
fn update_does_not_overwrite_rustfmt() {
826826
update_setup(&|config, self_dist| {
827-
expect_ok(config, &["rustup-init", "-y"]);
827+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
828828
let version = env!("CARGO_PKG_VERSION");
829829
output_release_file(self_dist, "1", version);
830830

@@ -866,7 +866,7 @@ fn update_does_not_overwrite_rustfmt() {
866866
#[test]
867867
fn update_installs_clippy_cargo_and() {
868868
update_setup(&|config, self_dist| {
869-
expect_ok(config, &["rustup-init", "-y"]);
869+
expect_ok(config, &["rustup-init", "-y", "--no-modify-path"]);
870870
let version = env!("CARGO_PKG_VERSION");
871871
output_release_file(self_dist, "1", version);
872872

tests/mock/clitools.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct Config {
4343
pub homedir: PathBuf,
4444
/// An empty directory. Tests should not write to this.
4545
pub emptydir: PathBuf,
46+
/// Root for updates to rustup itself aka RUSTUP_UPDATE_ROOT
47+
pub rustup_update_root: Option<String>,
4648
/// This is cwd for the test
4749
pub workdir: RefCell<PathBuf>,
4850
}
@@ -93,6 +95,7 @@ pub static MULTI_ARCH1: &str = "x86_64-unknown-linux-gnu";
9395
/// a mock dist server.
9496
pub fn setup(s: Scenario, f: &dyn Fn(&mut Config)) {
9597
// Unset env variables that will break our testing
98+
env::remove_var("RUSTUP_UPDATE_ROOT");
9699
env::remove_var("RUSTUP_TOOLCHAIN");
97100
env::remove_var("SHELL");
98101
env::remove_var("ZDOTDIR");
@@ -142,6 +145,7 @@ pub fn setup(s: Scenario, f: &dyn Fn(&mut Config)) {
142145
cargodir,
143146
homedir,
144147
emptydir,
148+
rustup_update_root: None,
145149
workdir: RefCell::new(workdir),
146150
};
147151

@@ -434,6 +438,10 @@ pub fn env<E: rustup_test::Env>(config: &Config, cmd: &mut E) {
434438
.unwrap()
435439
.join("tests/mock/signing-key.pub.asc"),
436440
);
441+
442+
if let Some(root) = config.rustup_update_root.as_ref() {
443+
cmd.env("RUSTUP_UPDATE_ROOT", root);
444+
}
437445
}
438446

439447
use std::sync::RwLock;

0 commit comments

Comments
 (0)