@@ -934,6 +934,9 @@ mod tests {
934
934
}
935
935
}
936
936
937
+ fn dummy_callback ( _: & str , _: usize ) { }
938
+
939
+
937
940
// Test acquiring with an alias
938
941
#[ test]
939
942
fn test_provider_with_alias ( ) {
@@ -943,10 +946,10 @@ mod tests {
943
946
// Adding alias to the provider
944
947
input. aliases = Some ( vec ! [ alias] ) ;
945
948
946
- let ( change_tx , _ ) = tokio :: sync :: mpsc :: channel :: < ( String , usize ) > ( 1 ) ;
949
+ let change_callback : ProviderConnectionChangeCallback = Arc :: new ( dummy_callback ) ;
947
950
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
948
951
// Create MultiProviderLineup with the provider and alias
949
- let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_tx ) ;
952
+ let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_callback ) ;
950
953
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
951
954
rt. block_on ( async move {
952
955
// Test that the alias provider is available
@@ -968,9 +971,9 @@ mod tests {
968
971
let alias = create_config_input_alias ( 2 , "http://alias.com" , 0 , 2 ) ;
969
972
// Adding alias with different priority
970
973
input. aliases = Some ( vec ! [ alias] ) ;
971
- let ( change_tx , _ ) = tokio :: sync :: mpsc :: channel :: < ( String , usize ) > ( 1 ) ;
974
+ let change_callback : ProviderConnectionChangeCallback = Arc :: new ( dummy_callback ) ;
972
975
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
973
- let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_tx ) ;
976
+ let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_callback ) ;
974
977
// The alias has a higher priority, so the alias should be acquired first
975
978
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
976
979
rt. block_on ( async move {
@@ -990,9 +993,9 @@ mod tests {
990
993
991
994
// Adding multiple aliases
992
995
input. aliases = Some ( vec ! [ alias1, alias2] ) ;
993
- let ( change_tx , _ ) = tokio :: sync :: mpsc :: channel :: < ( String , usize ) > ( 1 ) ;
996
+ let change_callback : ProviderConnectionChangeCallback = Arc :: new ( dummy_callback ) ;
994
997
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
995
- let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_tx ) ;
998
+ let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_callback ) ;
996
999
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
997
1000
rt. block_on ( async move {
998
1001
// The alias with priority 0 should be acquired first (higher priority)
@@ -1021,9 +1024,9 @@ mod tests {
1021
1024
1022
1025
// Adding alias
1023
1026
input. aliases = Some ( vec ! [ alias1, alias2] ) ;
1024
- let ( change_tx , _ ) = tokio :: sync :: mpsc :: channel :: < ( String , usize ) > ( 1 ) ;
1027
+ let change_callback : ProviderConnectionChangeCallback = Arc :: new ( dummy_callback ) ;
1025
1028
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
1026
- let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_tx ) ;
1029
+ let lineup = MultiProviderLineup :: new ( & input, Some ( dummy_get_connection) , & change_callback ) ;
1027
1030
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
1028
1031
rt. block_on ( async move {
1029
1032
// Acquire connection from alias2
@@ -1049,10 +1052,9 @@ mod tests {
1049
1052
#[ test]
1050
1053
fn test_acquire_when_capacity_available ( ) {
1051
1054
let cfg = create_config_input ( 1 , "provider5_1" , 1 , 2 ) ;
1052
- let on_connection_change = move |_name, _connections| { } ;
1053
- let change_tx = Arc :: new ( on_connection_change) ;
1055
+ let change_callback: ProviderConnectionChangeCallback = Arc :: new ( dummy_callback) ;
1054
1056
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
1055
- let lineup = SingleProviderLineup :: new ( & cfg, Some ( dummy_get_connection) , & change_tx ) ;
1057
+ let lineup = SingleProviderLineup :: new ( & cfg, Some ( dummy_get_connection) , & change_callback ) ;
1056
1058
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
1057
1059
rt. block_on ( async move {
1058
1060
// First acquire attempt should succeed
@@ -1071,11 +1073,10 @@ mod tests {
1071
1073
#[ test]
1072
1074
fn test_release_connection ( ) {
1073
1075
let cfg = create_config_input ( 1 , "provider7_1" , 1 , 2 ) ;
1074
- let on_connection_change = move |_name, _connections| { } ;
1075
- let change_tx = Arc :: new ( on_connection_change) ;
1076
+ let change_callback: ProviderConnectionChangeCallback = Arc :: new ( dummy_callback) ;
1076
1077
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
1077
1078
1078
- let lineup = SingleProviderLineup :: new ( & cfg, Some ( dummy_get_connection) , & change_tx ) ;
1079
+ let lineup = SingleProviderLineup :: new ( & cfg, Some ( dummy_get_connection) , & change_callback ) ;
1079
1080
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
1080
1081
rt. block_on ( async move {
1081
1082
// Acquire two connections
@@ -1103,9 +1104,9 @@ mod tests {
1103
1104
cfg1. aliases = Some ( vec ! [ alias] ) ;
1104
1105
1105
1106
// Create MultiProviderLineup with the provider and alias
1106
- let ( change_tx , _ ) = tokio :: sync :: mpsc :: channel :: < ( String , usize ) > ( 1 ) ;
1107
+ let change_callback : ProviderConnectionChangeCallback = Arc :: new ( dummy_callback ) ;
1107
1108
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
1108
- let lineup = MultiProviderLineup :: new ( & cfg1, Some ( dummy_get_connection) , & change_tx ) ;
1109
+ let lineup = MultiProviderLineup :: new ( & cfg1, Some ( dummy_get_connection) , & change_callback ) ;
1109
1110
let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
1110
1111
rt. block_on ( async move {
1111
1112
// Test acquiring the first provider
@@ -1136,10 +1137,9 @@ mod tests {
1136
1137
#[ test]
1137
1138
fn test_concurrent_acquire ( ) {
1138
1139
let cfg = create_config_input ( 1 , "provider9_1" , 1 , 2 ) ;
1139
- let on_connection_change = move |_name, _connections| { } ;
1140
- let change_tx = Arc :: new ( on_connection_change) ;
1140
+ let change_callback: ProviderConnectionChangeCallback = Arc :: new ( dummy_callback) ;
1141
1141
let dummy_get_connection = |_s : & str | -> Option < & ProviderConfigConnection > { None } ;
1142
- let lineup = Arc :: new ( SingleProviderLineup :: new ( & cfg, Some ( dummy_get_connection) , & change_tx ) ) ;
1142
+ let lineup = Arc :: new ( SingleProviderLineup :: new ( & cfg, Some ( dummy_get_connection) , & change_callback ) ) ;
1143
1143
1144
1144
let available_count = Arc :: new ( AtomicU16 :: new ( 2 ) ) ;
1145
1145
let grace_period_count = Arc :: new ( AtomicU16 :: new ( 1 ) ) ;
0 commit comments