@@ -355,6 +355,7 @@ mod tests {
355355 use super :: * ;
356356 use fluent_langneg:: { negotiate_languages, NegotiationStrategy } ;
357357 use intl_pluralrules:: { PluralCategory , PluralRuleType , PluralRules as IntlPluralRules } ;
358+ use std:: { sync:: Arc , thread} ;
358359
359360 struct PluralRules ( pub IntlPluralRules ) ;
360361
@@ -385,7 +386,7 @@ mod tests {
385386 }
386387
387388 #[ test]
388- fn it_works ( ) {
389+ fn test_single_thread ( ) {
389390 let lang: LanguageIdentifier = "en" . parse ( ) . unwrap ( ) ;
390391
391392 let mut memoizer = IntlMemoizer :: default ( ) ;
@@ -407,4 +408,28 @@ mod tests {
407408 assert_eq ! ( result, Ok ( PluralCategory :: OTHER ) ) ;
408409 }
409410 }
411+
412+ #[ test]
413+ fn test_concurrent ( ) {
414+ let lang: LanguageIdentifier = "en" . parse ( ) . unwrap ( ) ;
415+ let memoizer = Arc :: new ( concurrent:: IntlLangMemoizer :: new ( lang) ) ;
416+ let mut threads = vec ! [ ] ;
417+
418+ // Spawn four threads that all use the PluralRules.
419+ for _ in 0 ..4 {
420+ let memoizer = Arc :: clone ( & memoizer) ;
421+ threads. push ( thread:: spawn ( move || {
422+ memoizer
423+ . with_try_get :: < PluralRules , _ , _ > ( ( PluralRuleType :: CARDINAL , ) , |cb| {
424+ cb. 0 . select ( 5 )
425+ } )
426+ . expect ( "Failed to get a PluralRules result." )
427+ } ) ) ;
428+ }
429+
430+ for thread in threads. drain ( ..) {
431+ let result = thread. join ( ) . expect ( "Failed to join thread." ) ;
432+ assert_eq ! ( result, Ok ( PluralCategory :: OTHER ) ) ;
433+ }
434+ }
410435}
0 commit comments