@@ -355,6 +355,7 @@ mod tests {
355
355
use super :: * ;
356
356
use fluent_langneg:: { negotiate_languages, NegotiationStrategy } ;
357
357
use intl_pluralrules:: { PluralCategory , PluralRuleType , PluralRules as IntlPluralRules } ;
358
+ use std:: { sync:: Arc , thread} ;
358
359
359
360
struct PluralRules ( pub IntlPluralRules ) ;
360
361
@@ -385,7 +386,7 @@ mod tests {
385
386
}
386
387
387
388
#[ test]
388
- fn it_works ( ) {
389
+ fn test_single_thread ( ) {
389
390
let lang: LanguageIdentifier = "en" . parse ( ) . unwrap ( ) ;
390
391
391
392
let mut memoizer = IntlMemoizer :: default ( ) ;
@@ -407,4 +408,28 @@ mod tests {
407
408
assert_eq ! ( result, Ok ( PluralCategory :: OTHER ) ) ;
408
409
}
409
410
}
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
+ }
410
435
}
0 commit comments