@@ -145,11 +145,14 @@ fn test_get_region_local_state() {
145
145
cluster. shutdown ( ) ;
146
146
}
147
147
148
+ /// When a learner peer is removed by conf change, it will not wait until the conf change.
149
+ /// However, leader could stop sending raft messages to the peer at an earlier stage,
150
+ /// the peer is eventually removed by stale peer checking.
148
151
#[ test]
149
152
fn test_stale_peer ( ) {
150
153
let ( mut cluster, pd_client) = new_mock_cluster ( 0 , 2 ) ;
151
154
152
- cluster. cfg . raft_store . max_leader_missing_duration = ReadableDuration :: secs ( 6 ) ;
155
+ cluster. cfg . raft_store . max_leader_missing_duration = ReadableDuration :: secs ( 4 ) ;
153
156
154
157
pd_client. disable_default_operator ( ) ;
155
158
disable_auto_gen_compact_log ( & mut cluster) ;
@@ -173,14 +176,17 @@ fn test_stale_peer() {
173
176
check_key ( & cluster, b"k2" , b"v" , Some ( false ) , None , Some ( vec ! [ 2 ] ) ) ;
174
177
175
178
pd_client. must_remove_peer ( 1 , p2. clone ( ) ) ;
176
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 1500 ) ) ;
179
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 1000 ) ) ;
177
180
178
181
fail:: cfg ( "proxy_record_all_messages" , "return(1)" ) ;
179
182
cluster. clear_send_filters ( ) ;
180
183
181
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 1500 ) ) ;
184
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 1000 ) ) ;
182
185
check_key ( & cluster, b"k2" , b"v" , Some ( false ) , None , Some ( vec ! [ 2 ] ) ) ;
183
- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 6000 ) ) ;
186
+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 3000 ) ) ;
187
+ // Must received a gc peer message.
188
+ /// "receives gc message, trying to remove"
189
+ /// "raft message is stale, tell to gc"
184
190
assert_ne ! (
185
191
cluster
186
192
. get_debug_struct( )
@@ -189,4 +195,5 @@ fn test_stale_peer() {
189
195
. load( Ordering :: SeqCst ) ,
190
196
0
191
197
) ;
198
+ fail:: remove ( "proxy_record_all_messages" )
192
199
}
0 commit comments