Skip to content

Commit 13f3d55

Browse files
authored
Merge pull request #173 from rage/csharp-fix
use mutex in csharp tests
2 parents 80f639d + 1d77e2d commit 13f3d55

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

plugins/csharp/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ walkdir = "2"
1818
zip = "0.5"
1919

2020
[dev-dependencies]
21+
once_cell = "1"
2122
simple_logger = "1"
2223
tempfile = "3"

plugins/csharp/src/plugin.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,13 @@ impl LanguagePlugin for CSharpPlugin {
350350
#[cfg(test)]
351351
mod test {
352352
use super::*;
353-
use std::sync::Once;
353+
use once_cell::sync::Lazy;
354+
use std::sync::{Mutex, Once};
354355
use tempfile::TempDir;
355356

356357
static INIT_RUNNER: Once = Once::new();
358+
// running the runner in parallel seems to sometimes make tests run for an excessively long time
359+
static MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
357360

358361
fn init() {
359362
use log::*;
@@ -524,6 +527,7 @@ mod test {
524527
#[test]
525528
fn scans_exercise() {
526529
init();
530+
let _lock = MUTEX.lock().unwrap();
527531

528532
let temp = dir_to_temp("tests/data/passing-exercise");
529533
let plugin = CSharpPlugin::new();
@@ -537,6 +541,7 @@ mod test {
537541
#[test]
538542
fn runs_tests_passing() {
539543
init();
544+
let _lock = MUTEX.lock().unwrap();
540545

541546
let temp = dir_to_temp("tests/data/passing-exercise");
542547
let plugin = CSharpPlugin::new();
@@ -553,6 +558,7 @@ mod test {
553558
#[test]
554559
fn runs_tests_failing() {
555560
init();
561+
let _lock = MUTEX.lock().unwrap();
556562

557563
let temp = dir_to_temp("tests/data/failing-exercise");
558564
let plugin = CSharpPlugin::new();
@@ -571,6 +577,7 @@ mod test {
571577
#[test]
572578
fn runs_tests_compile_err() {
573579
init();
580+
let _lock = MUTEX.lock().unwrap();
574581

575582
let temp = dir_to_temp("tests/data/non-compiling-exercise");
576583
let plugin = CSharpPlugin::new();
@@ -588,6 +595,7 @@ mod test {
588595
#[test]
589596
fn runs_tests_timeout() {
590597
init();
598+
let _lock = MUTEX.lock().unwrap();
591599

592600
let temp = dir_to_temp("tests/data/passing-exercise");
593601
let plugin = CSharpPlugin::new();
@@ -600,6 +608,7 @@ mod test {
600608
#[test]
601609
fn cleans() {
602610
init();
611+
let _lock = MUTEX.lock().unwrap();
603612

604613
let temp = dir_to_temp("tests/data/passing-exercise");
605614
let plugin = CSharpPlugin::new();
@@ -637,6 +646,7 @@ mod test {
637646
#[test]
638647
fn doesnt_give_points_unless_all_relevant_exercises_pass() {
639648
init();
649+
let _lock = MUTEX.lock().unwrap();
640650

641651
let temp = dir_to_temp("tests/data/partially-passing");
642652
let plugin = CSharpPlugin::new();

0 commit comments

Comments
 (0)