@@ -231,24 +231,37 @@ mod test {
231231 use super :: super :: { TestCase , TestCaseStatus } ;
232232 use super :: * ;
233233 use std:: fs:: { self , File } ;
234+ use std:: sync:: { Mutex , MutexGuard } ;
234235 use tempfile:: { tempdir, TempDir } ;
235236 use tmc_langs_framework:: domain:: Strategy ;
236237 use tmc_langs_framework:: zip:: ZipArchive ;
237238 use walkdir:: WalkDir ;
238239
239240 #[ cfg( windows) ]
240- use std:: sync:: Once ;
241- #[ cfg( windows) ]
242- static INIT_MAVEN : Once = Once :: new ( ) ;
241+ lazy_static:: lazy_static! {
242+ static ref MAVEN_LOCK : Mutex <( ) > = Mutex :: new( ( ) ) ;
243+ }
244+
245+ #[ cfg( not( windows) ) ]
246+ thread_local ! {
247+ static MAVEN_LOCK : Mutex <( ) > = Mutex :: new( ( ) ) ;
248+ }
243249
244250 fn init ( ) {
245251 let _ = env_logger:: builder ( ) . is_test ( true ) . try_init ( ) ;
252+ }
246253
247- // initializes maven in a synchronized manner for all tests
248- #[ cfg( windows) ]
249- INIT_MAVEN . call_once ( || {
250- MavenPlugin :: new ( ) . expect ( "failed to instantiate maven" ) ;
251- } ) ;
254+ #[ cfg( windows) ]
255+ fn get_maven ( ) -> ( MavenPlugin , MutexGuard < ' static , ( ) > ) {
256+ ( MavenPlugin :: new ( ) . unwrap ( ) , MAVEN_LOCK . lock ( ) . unwrap ( ) )
257+ }
258+
259+ #[ cfg( not( windows) ) ]
260+ fn get_maven ( ) -> ( MavenPlugin , MutexGuard < ' static , ( ) > ) {
261+ (
262+ MavenPlugin :: new ( ) . unwrap ( ) ,
263+ MAVEN_LOCK . with ( |_| Mutex :: new ( ( ) ) ) . lock ( ) . unwrap ( ) ,
264+ )
252265 }
253266
254267 fn copy_test_dir ( path : & str ) -> TempDir {
@@ -273,13 +286,12 @@ mod test {
273286 }
274287
275288 #[ test]
276- #[ cfg( not( target_os = "windows" ) ) ] // CI problems
277289 fn gets_project_class_path ( ) {
278290 init ( ) ;
279291
280292 let temp_dir = copy_test_dir ( "tests/data/maven_exercise" ) ;
281293 let test_path = temp_dir. path ( ) ;
282- let plugin = MavenPlugin :: new ( ) . unwrap ( ) ;
294+ let ( plugin, _lock ) = get_maven ( ) ;
283295 let class_path = plugin. get_project_class_path ( test_path) . unwrap ( ) ;
284296 log:: debug!( "{}" , class_path) ;
285297 let expected = format ! ( "{0}junit{0}" , std:: path:: MAIN_SEPARATOR ) ;
@@ -295,19 +307,18 @@ mod test {
295307
296308 let temp_dir = copy_test_dir ( "tests/data/maven_exercise" ) ;
297309 let test_path = temp_dir. path ( ) ;
298- let plugin = MavenPlugin :: new ( ) . unwrap ( ) ;
310+ let ( plugin, _lock ) = get_maven ( ) ;
299311 let compile_result = plugin. build ( test_path) . unwrap ( ) ;
300312 assert ! ( compile_result. status_code. success( ) ) ;
301313 }
302314
303315 #[ test]
304- #[ cfg( not( target_os = "windows" ) ) ] // CI problems
305316 fn creates_run_result_file ( ) {
306317 init ( ) ;
307318
308319 let temp_dir = copy_test_dir ( "tests/data/maven_exercise" ) ;
309320 let test_path = temp_dir. path ( ) ;
310- let plugin = MavenPlugin :: new ( ) . unwrap ( ) ;
321+ let ( plugin, _lock ) = get_maven ( ) ;
311322 let compile_result = plugin. build ( test_path) . unwrap ( ) ;
312323 let test_run = plugin
313324 . create_run_result_file ( test_path, compile_result)
@@ -338,7 +349,7 @@ mod test {
338349
339350 let temp_dir = copy_test_dir ( "tests/data/maven_exercise" ) ;
340351 let test_path = temp_dir. path ( ) ;
341- let plugin = MavenPlugin :: new ( ) . unwrap ( ) ;
352+ let ( plugin, _lock ) = get_maven ( ) ;
342353 let exercises = plugin
343354 . scan_exercise ( & test_path, "test" . to_string ( ) , & mut vec ! [ ] )
344355 . unwrap ( ) ;
@@ -357,7 +368,7 @@ mod test {
357368
358369 let temp_dir = copy_test_dir ( "tests/data/maven_exercise" ) ;
359370 let test_path = temp_dir. path ( ) ;
360- let plugin = MavenPlugin :: new ( ) . unwrap ( ) ;
371+ let ( plugin, _lock ) = get_maven ( ) ;
361372 let checkstyle_result = plugin
362373 . check_code_style ( test_path, Language :: from_639_3 ( "fin" ) . unwrap ( ) )
363374 . unwrap ( )
0 commit comments