mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-02-04 21:18:32 +00:00
test(git): enable fsync
for git operations (#3889)
* test(git): enable `fsync` for git operations * add comment
This commit is contained in:
parent
9de06769d3
commit
ff490b67ad
@ -473,18 +473,6 @@ mod tests {
|
|||||||
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer};
|
use crate::test::{fixture_repo, FixtureProvider, ModuleRenderer};
|
||||||
use crate::utils::create_command;
|
use crate::utils::create_command;
|
||||||
|
|
||||||
/// Right after the calls to git the filesystem state may not have finished
|
|
||||||
/// updating yet causing some of the tests to fail. These barriers are placed
|
|
||||||
/// after each call to git.
|
|
||||||
/// This barrier is windows-specific though other operating systems may need it
|
|
||||||
/// in the future.
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
fn barrier() {}
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn barrier() {
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn format_output(symbols: &str) -> Option<String> {
|
fn format_output(symbols: &str) -> Option<String> {
|
||||||
Some(format!(
|
Some(format!(
|
||||||
@ -705,7 +693,6 @@ mod tests {
|
|||||||
.args(&["config", "status.showUntrackedFiles", "no"])
|
.args(&["config", "status.showUntrackedFiles", "no"])
|
||||||
.current_dir(repo_dir.path())
|
.current_dir(repo_dir.path())
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("git_status")
|
let actual = ModuleRenderer::new("git_status")
|
||||||
.path(&repo_dir.path())
|
.path(&repo_dir.path())
|
||||||
@ -719,7 +706,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn shows_stashed() -> io::Result<()> {
|
fn shows_stashed() -> io::Result<()> {
|
||||||
let repo_dir = fixture_repo(FixtureProvider::Git)?;
|
let repo_dir = fixture_repo(FixtureProvider::Git)?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_stash(repo_dir.path())?;
|
create_stash(repo_dir.path())?;
|
||||||
|
|
||||||
@ -727,7 +713,6 @@ mod tests {
|
|||||||
.args(&["reset", "--hard", "HEAD"])
|
.args(&["reset", "--hard", "HEAD"])
|
||||||
.current_dir(repo_dir.path())
|
.current_dir(repo_dir.path())
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("git_status")
|
let actual = ModuleRenderer::new("git_status")
|
||||||
.path(&repo_dir.path())
|
.path(&repo_dir.path())
|
||||||
@ -741,16 +726,13 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn shows_stashed_with_count() -> io::Result<()> {
|
fn shows_stashed_with_count() -> io::Result<()> {
|
||||||
let repo_dir = fixture_repo(FixtureProvider::Git)?;
|
let repo_dir = fixture_repo(FixtureProvider::Git)?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_stash(repo_dir.path())?;
|
create_stash(repo_dir.path())?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["reset", "--hard", "HEAD"])
|
.args(&["reset", "--hard", "HEAD"])
|
||||||
.current_dir(repo_dir.path())
|
.current_dir(repo_dir.path())
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("git_status")
|
let actual = ModuleRenderer::new("git_status")
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
@ -1014,7 +996,6 @@ mod tests {
|
|||||||
|
|
||||||
fs::remove_file(repo_dir.path().join("a"))?;
|
fs::remove_file(repo_dir.path().join("a"))?;
|
||||||
fs::rename(repo_dir.path().join("b"), repo_dir.path().join("c"))?;
|
fs::rename(repo_dir.path().join("b"), repo_dir.path().join("c"))?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("git_status")
|
let actual = ModuleRenderer::new("git_status")
|
||||||
.path(&repo_dir.path())
|
.path(&repo_dir.path())
|
||||||
@ -1040,7 +1021,6 @@ mod tests {
|
|||||||
.args(&["commit", "-am", "Update readme", "--no-gpg-sign"])
|
.args(&["commit", "-am", "Update readme", "--no-gpg-sign"])
|
||||||
.current_dir(&repo_dir)
|
.current_dir(&repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1050,7 +1030,6 @@ mod tests {
|
|||||||
.args(&["reset", "--hard", "HEAD^"])
|
.args(&["reset", "--hard", "HEAD^"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1060,7 +1039,6 @@ mod tests {
|
|||||||
.args(&["reset", "--hard", "HEAD^"])
|
.args(&["reset", "--hard", "HEAD^"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
fs::write(repo_dir.join("Cargo.toml"), " ")?;
|
fs::write(repo_dir.join("Cargo.toml"), " ")?;
|
||||||
|
|
||||||
@ -1068,7 +1046,6 @@ mod tests {
|
|||||||
.args(&["commit", "-am", "Update readme", "--no-gpg-sign"])
|
.args(&["commit", "-am", "Update readme", "--no-gpg-sign"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1078,7 +1055,6 @@ mod tests {
|
|||||||
.args(&["reset", "--hard", "HEAD^"])
|
.args(&["reset", "--hard", "HEAD^"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
fs::write(repo_dir.join("readme.md"), "# goodbye")?;
|
fs::write(repo_dir.join("readme.md"), "# goodbye")?;
|
||||||
|
|
||||||
@ -1086,32 +1062,27 @@ mod tests {
|
|||||||
.args(&["add", "."])
|
.args(&["add", "."])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["commit", "-m", "Change readme", "--no-gpg-sign"])
|
.args(&["commit", "-m", "Change readme", "--no-gpg-sign"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["pull", "--rebase"])
|
.args(&["pull", "--rebase"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_stash(repo_dir: &Path) -> io::Result<()> {
|
fn create_stash(repo_dir: &Path) -> io::Result<()> {
|
||||||
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
File::create(repo_dir.join("readme.md"))?.sync_all()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["stash", "--all"])
|
.args(&["stash", "--all"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1129,7 +1100,6 @@ mod tests {
|
|||||||
.args(&["add", "-A", "-N"])
|
.args(&["add", "-A", "-N"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1147,7 +1117,6 @@ mod tests {
|
|||||||
.args(&["add", "."])
|
.args(&["add", "."])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1160,7 +1129,6 @@ mod tests {
|
|||||||
.args(&["add", "."])
|
.args(&["add", "."])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
writeln!(&mut file, "modified")?;
|
writeln!(&mut file, "modified")?;
|
||||||
file.sync_all()?;
|
file.sync_all()?;
|
||||||
@ -1173,13 +1141,11 @@ mod tests {
|
|||||||
.args(&["mv", "readme.md", "readme.md.bak"])
|
.args(&["mv", "readme.md", "readme.md.bak"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["add", "-A"])
|
.args(&["add", "-A"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1189,13 +1155,11 @@ mod tests {
|
|||||||
.args(&["mv", "readme.md", "readme.md.bak"])
|
.args(&["mv", "readme.md", "readme.md.bak"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["add", "-A"])
|
.args(&["add", "-A"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
let mut file = File::create(repo_dir.join("readme.md.bak"))?;
|
let mut file = File::create(repo_dir.join("readme.md.bak"))?;
|
||||||
writeln!(&mut file, "modified")?;
|
writeln!(&mut file, "modified")?;
|
||||||
@ -1219,7 +1183,6 @@ mod tests {
|
|||||||
.args(&["add", ".gitignore"])
|
.args(&["add", ".gitignore"])
|
||||||
.current_dir(repo_dir)
|
.current_dir(repo_dir)
|
||||||
.output()?;
|
.output()?;
|
||||||
barrier();
|
|
||||||
|
|
||||||
let mut file = File::create(repo_dir.join("ignored.txt"))?;
|
let mut file = File::create(repo_dir.join("ignored.txt"))?;
|
||||||
writeln!(&mut file, "modified")?;
|
writeln!(&mut file, "modified")?;
|
||||||
|
@ -188,6 +188,21 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result<TempDir> {
|
|||||||
.current_dir(&path.path())
|
.current_dir(&path.path())
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
|
// Prevent intermittent test failures and ensure that the result of git commands
|
||||||
|
// are available during I/O-contentious tests, by having git run `fsync`.
|
||||||
|
// This is especially important on Windows.
|
||||||
|
// Newer, more far-reaching git setting for `fsync`, that's not yet widely supported:
|
||||||
|
create_command("git")?
|
||||||
|
.args(&["config", "--local", "core.fsync", "all"])
|
||||||
|
.current_dir(&path.path())
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
// Older git setting for `fsync` for compatibility with older git versions:
|
||||||
|
create_command("git")?
|
||||||
|
.args(&["config", "--local", "core.fsyncObjectFiles", "true"])
|
||||||
|
.current_dir(&path.path())
|
||||||
|
.output()?;
|
||||||
|
|
||||||
create_command("git")?
|
create_command("git")?
|
||||||
.args(&["reset", "--hard", "HEAD"])
|
.args(&["reset", "--hard", "HEAD"])
|
||||||
.current_dir(&path.path())
|
.current_dir(&path.path())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user