@@ -536,8 +536,14 @@ struct CredentialsFromInstanceMetadata {
536536mod tests {
537537 use super :: * ;
538538 use std:: io:: Write ;
539+ use std:: sync:: Mutex ;
540+ use std:: sync:: OnceLock ;
539541 use tempfile:: NamedTempFile ;
540542
543+ /// Serializes container-credentials tests that touch RELATIVE_URI/FULL_URI so parallel runs don't race.
544+ #[ cfg( feature = "http-credentials" ) ]
545+ static CONTAINER_CREDENTIALS_TEST_LOCK : OnceLock < Mutex < ( ) > > = OnceLock :: new ( ) ;
546+
541547 fn create_test_credentials_file ( content : & str ) -> NamedTempFile {
542548 let mut file = NamedTempFile :: new ( ) . unwrap ( ) ;
543549 file. write_all ( content. as_bytes ( ) ) . unwrap ( ) ;
@@ -605,6 +611,10 @@ aws_secret_access_key = SECRET
605611 #[ cfg( feature = "http-credentials" ) ]
606612 #[ test]
607613 fn test_container_credentials_not_container_when_no_env ( ) {
614+ let _lock = CONTAINER_CREDENTIALS_TEST_LOCK
615+ . get_or_init ( || Mutex :: new ( ( ) ) )
616+ . lock ( )
617+ . unwrap ( ) ;
608618 let _guard = EnvGuard :: remove ( & [
609619 "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI" ,
610620 "AWS_CONTAINER_CREDENTIALS_FULL_URI" ,
@@ -616,6 +626,10 @@ aws_secret_access_key = SECRET
616626 #[ cfg( feature = "http-credentials" ) ]
617627 #[ test]
618628 fn test_container_credentials_relative_uri_precedence ( ) {
629+ let _lock = CONTAINER_CREDENTIALS_TEST_LOCK
630+ . get_or_init ( || Mutex :: new ( ( ) ) )
631+ . lock ( )
632+ . unwrap ( ) ;
619633 let _guard = EnvGuard :: set (
620634 "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI" ,
621635 "/v2/credentials/x" ,
@@ -635,6 +649,10 @@ aws_secret_access_key = SECRET
635649 #[ cfg( feature = "http-credentials" ) ]
636650 #[ test]
637651 fn test_container_credentials_full_uri_used_when_no_relative ( ) {
652+ let _lock = CONTAINER_CREDENTIALS_TEST_LOCK
653+ . get_or_init ( || Mutex :: new ( ( ) ) )
654+ . lock ( )
655+ . unwrap ( ) ;
638656 let _guard = EnvGuard :: set (
639657 "AWS_CONTAINER_CREDENTIALS_FULL_URI" ,
640658 "http://169.254.170.23/v1/credentials" ,
0 commit comments