ok/jj
1
0
Fork 0
forked from mirrors/jj

tests: use one thread per core in concurrency tests

The tests have been failing in GitHub's CI quite frequently. It's
about time I try to do something about it. Let's see if this helps.
This commit is contained in:
Martin von Zweigbergk 2021-04-28 23:51:58 -07:00
parent 46edbbef09
commit 419002fab4
5 changed files with 19 additions and 10 deletions

1
Cargo.lock generated
View file

@ -582,6 +582,7 @@ dependencies = [
"git2",
"hex",
"maplit",
"num_cpus",
"pest",
"pest_derive",
"protobuf",

View file

@ -38,4 +38,5 @@ whoami = "1.0.1"
zstd = "0.6.0"
[dev-dependencies]
num_cpus = "1.13.0"
test-case = "1.0.0"

View file

@ -65,6 +65,7 @@ impl Drop for FileLock {
#[cfg(test)]
mod tests {
use std::cmp::max;
use std::{env, thread};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
@ -94,8 +95,9 @@ mod tests {
.open(data_path.clone())
.unwrap();
data_file.write_u32::<LittleEndian>(0).unwrap();
let num_threads = max(num_cpus::get(), 4);
let mut threads = vec![];
for _ in 0..100 {
for _ in 0..num_threads {
let data_path = data_path.clone();
let lock_path = lock_path.clone();
let handle = thread::spawn(move || {
@ -116,6 +118,6 @@ mod tests {
}
let mut data_file = OpenOptions::new().read(true).open(data_path).unwrap();
let value = data_file.read_u32::<LittleEndian>().unwrap();
assert_eq!(value, 100);
assert_eq!(value, num_threads as u32);
}
}

View file

@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::cmp::max;
use std::thread;
use jujube_lib::repo::ReadonlyRepo;
use jujube_lib::{dag_walk, testutils};
use test_case::test_case;
fn count_non_merge_operations(repo: &ReadonlyRepo) -> u32 {
fn count_non_merge_operations(repo: &ReadonlyRepo) -> usize {
let op_store = repo.op_store();
let op_id = repo.op_id().clone();
let mut num_ops = 0;
@ -45,8 +46,9 @@ fn test_commit_parallel(use_git: bool) {
let settings = testutils::user_settings();
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
let num_threads = max(num_cpus::get(), 4);
let mut threads = vec![];
for _ in 0..100 {
for _ in 0..num_threads {
let settings = settings.clone();
let repo = repo.clone();
let handle = thread::spawn(move || {
@ -61,11 +63,11 @@ fn test_commit_parallel(use_git: bool) {
let repo = repo.reload().unwrap();
// One commit per thread plus the commit from the initial checkout on top of the
// root commit
assert_eq!(repo.view().heads().len(), 101);
assert_eq!(repo.view().heads().len(), num_threads + 1);
// One operation for initializing the repo (containing the root id and the
// initial working copy commit).
assert_eq!(count_non_merge_operations(&repo), 101);
assert_eq!(count_non_merge_operations(&repo), num_threads + 1);
}
#[cfg(unix)]
@ -77,8 +79,9 @@ fn test_commit_parallel_instances(use_git: bool) {
let settings = testutils::user_settings();
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
let num_threads = max(num_cpus::get(), 4);
let mut threads = vec![];
for _ in 0..100 {
for _ in 0..num_threads {
let settings = settings.clone();
let repo = ReadonlyRepo::load(&settings, repo.working_copy_path().clone()).unwrap();
let handle = thread::spawn(move || {
@ -93,9 +96,9 @@ fn test_commit_parallel_instances(use_git: bool) {
// One commit per thread plus the commit from the initial checkout on top of the
// root commit
let repo = ReadonlyRepo::load(&settings, repo.working_copy_path().clone()).unwrap();
assert_eq!(repo.view().heads().len(), 101);
assert_eq!(repo.view().heads().len(), num_threads + 1);
// One operation for initializing the repo (containing the root id and the
// initial working copy commit).
assert_eq!(count_non_merge_operations(&repo), 101);
assert_eq!(count_non_merge_operations(&repo), num_threads + 1);
}

View file

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::cmp::max;
use std::collections::HashSet;
use std::thread;
@ -104,8 +105,9 @@ fn test_checkout_parallel(use_git: bool) {
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
let store = repo.store();
let num_threads = max(num_cpus::get(), 4);
let mut commit_ids = vec![];
for i in 0..100 {
for i in 0..num_threads {
let path = FileRepoPath::from(format!("file{}", i).as_str());
let tree = testutils::create_tree(&repo, &[(&path, "contents")]);
let commit = CommitBuilder::for_new_commit(&settings, store, tree.id().clone())