tests: don't create workspaces in operation tests

This commit is contained in:
Martin von Zweigbergk 2022-02-05 15:31:20 -08:00
parent 2eb46fda8a
commit 2af6b4c58d

View File

@ -32,8 +32,8 @@ fn list_dir(dir: &Path) -> Vec<String> {
fn test_unpublished_operation(use_git: bool) { fn test_unpublished_operation(use_git: bool) {
// Test that the operation doesn't get published until that's requested. // Test that the operation doesn't get published until that's requested.
let settings = testutils::user_settings(); let settings = testutils::user_settings();
let test_workspace = testutils::init_workspace(&settings, use_git); let test_repo = testutils::init_repo(&settings, use_git);
let repo = &test_workspace.repo; let repo = &test_repo.repo;
let op_heads_dir = repo.repo_path().join("op_heads"); let op_heads_dir = repo.repo_path().join("op_heads");
let op_id0 = repo.op_id().clone(); let op_id0 = repo.op_id().clone();
@ -55,8 +55,8 @@ fn test_consecutive_operations(use_git: bool) {
// Test that consecutive operations result in a single op-head on disk after // Test that consecutive operations result in a single op-head on disk after
// each operation // each operation
let settings = testutils::user_settings(); let settings = testutils::user_settings();
let test_workspace = testutils::init_workspace(&settings, use_git); let test_repo = testutils::init_repo(&settings, use_git);
let repo = &test_workspace.repo; let repo = &test_repo.repo;
let op_heads_dir = repo.repo_path().join("op_heads"); let op_heads_dir = repo.repo_path().join("op_heads");
let op_id0 = repo.op_id().clone(); let op_id0 = repo.op_id().clone();
@ -88,8 +88,8 @@ fn test_concurrent_operations(use_git: bool) {
// Test that consecutive operations result in multiple op-heads on disk until // Test that consecutive operations result in multiple op-heads on disk until
// the repo has been reloaded (which currently happens right away). // the repo has been reloaded (which currently happens right away).
let settings = testutils::user_settings(); let settings = testutils::user_settings();
let test_workspace = testutils::init_workspace(&settings, use_git); let test_repo = testutils::init_repo(&settings, use_git);
let repo = &test_workspace.repo; let repo = &test_repo.repo;
let op_heads_dir = repo.repo_path().join("op_heads"); let op_heads_dir = repo.repo_path().join("op_heads");
let op_id0 = repo.op_id().clone(); let op_id0 = repo.op_id().clone();
@ -133,10 +133,9 @@ fn assert_heads(repo: RepoRef, expected: Vec<&CommitId>) {
fn test_isolation(use_git: bool) { fn test_isolation(use_git: bool) {
// Test that two concurrent transactions don't see each other's changes. // Test that two concurrent transactions don't see each other's changes.
let settings = testutils::user_settings(); let settings = testutils::user_settings();
let test_workspace = testutils::init_workspace(&settings, use_git); let test_repo = testutils::init_repo(&settings, use_git);
let repo = &test_workspace.repo; let repo = &test_repo.repo;
let checkout_id = repo.view().checkout().clone();
let mut tx = repo.start_transaction("test"); let mut tx = repo.start_transaction("test");
let initial = testutils::create_random_commit(&settings, repo) let initial = testutils::create_random_commit(&settings, repo)
.set_parents(vec![repo.store().root_commit_id().clone()]) .set_parents(vec![repo.store().root_commit_id().clone()])
@ -148,9 +147,9 @@ fn test_isolation(use_git: bool) {
let mut tx2 = repo.start_transaction("transaction 2"); let mut tx2 = repo.start_transaction("transaction 2");
let mut_repo2 = tx2.mut_repo(); let mut_repo2 = tx2.mut_repo();
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]); assert_heads(repo.as_repo_ref(), vec![initial.id()]);
assert_heads(mut_repo1.as_repo_ref(), vec![&checkout_id, initial.id()]); assert_heads(mut_repo1.as_repo_ref(), vec![initial.id()]);
assert_heads(mut_repo2.as_repo_ref(), vec![&checkout_id, initial.id()]); assert_heads(mut_repo2.as_repo_ref(), vec![initial.id()]);
let rewrite1 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial) let rewrite1 = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial)
.set_description("rewrite1".to_string()) .set_description("rewrite1".to_string())
@ -161,31 +160,22 @@ fn test_isolation(use_git: bool) {
// Neither transaction has committed yet, so each transaction sees its own // Neither transaction has committed yet, so each transaction sees its own
// commit. // commit.
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]); assert_heads(repo.as_repo_ref(), vec![initial.id()]);
assert_heads( assert_heads(mut_repo1.as_repo_ref(), vec![initial.id(), rewrite1.id()]);
mut_repo1.as_repo_ref(), assert_heads(mut_repo2.as_repo_ref(), vec![initial.id(), rewrite2.id()]);
vec![&checkout_id, initial.id(), rewrite1.id()],
);
assert_heads(
mut_repo2.as_repo_ref(),
vec![&checkout_id, initial.id(), rewrite2.id()],
);
// The base repo and tx2 don't see the commits from tx1. // The base repo and tx2 don't see the commits from tx1.
tx1.commit(); tx1.commit();
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]); assert_heads(repo.as_repo_ref(), vec![initial.id()]);
assert_heads( assert_heads(mut_repo2.as_repo_ref(), vec![initial.id(), rewrite2.id()]);
mut_repo2.as_repo_ref(),
vec![&checkout_id, initial.id(), rewrite2.id()],
);
// The base repo still doesn't see the commits after both transactions commit. // The base repo still doesn't see the commits after both transactions commit.
tx2.commit(); tx2.commit();
assert_heads(repo.as_repo_ref(), vec![&checkout_id, initial.id()]); assert_heads(repo.as_repo_ref(), vec![initial.id()]);
// After reload, the base repo sees both rewrites. // After reload, the base repo sees both rewrites.
let repo = repo.reload(); let repo = repo.reload();
assert_heads( assert_heads(
repo.as_repo_ref(), repo.as_repo_ref(),
vec![&checkout_id, initial.id(), rewrite1.id(), rewrite2.id()], vec![initial.id(), rewrite1.id(), rewrite2.id()],
); );
} }