You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: test_stale_read.rs
    path of file: ./repos/tikv/tests/integrations/raftstore
    
    the code of the file until where you have to start completion: // Copyright 2016 TiKV Project Authors. Licensed under Apache-2.0.

use std::{cell::RefCell, sync::Arc, time::Duration};

use grpcio::{ChannelBuilder, Environment};
use kvproto::{
    kvrpcpb::{Context, Op},
    metapb::{Peer, Region},
    tikvpb_grpc::TikvClient,
};
use test_raftstore::{must_get_equal, new_mutation, new_peer};
use test_raftstore_macro::test_case;
use tikv_util::{config::ReadableDuration, time::Instant};

use crate::tikv_util::HandyRwLock;

#[test_case(test_raftstore::new_server_cluster)]
#[test_case(test_raftstore_v2::new_server_cluster)]
fn test_stale_read_with_ts0() {
    let mut cluster = new_cluster(0, 3);
    let pd_client = Arc::clone(&cluster.pd_client);
    pd_client.disable_default_operator();
    cluster.cfg.resolved_ts.enable = true;
    cluster.cfg.resolved_ts.advance_ts_interval = ReadableDuration::millis(200);
    cluster.run();

    let region_id = 1;
    let env = Arc::new(Environment::new(1));
    let new_client = |peer: Peer| {
        let cli = TikvClient::new(
            ChannelBuilder::new(env.clone())
                .connect(&cluster.sim.rl().get_addr(peer.get_store_id())),
        );
        let epoch = cluster.get_region_epoch(region_id);
        let mut ctx = Context::default();
        ctx.set_region_id(region_id);
        ctx.set_peer(peer);
        ctx.set_region_epoch(epoch);
        PeerClient { cli, ctx }
    };
    let leader = new_peer(1, 1);
    let mut leader_client = ne
    
fn test_stale_read_resolved_ts_advance() {
    let mut cluster = new_cluster(0, 3);
    cluster.cfg.resolved_ts.enable = true;
    cluster.cfg.resolved_ts.advance_ts_interval = ReadableDuration::millis(200);
    let pd_client = cluster.pd_client.clone();
    pd_client.disable_default_operator();

    cluster.run_conf_change();
    let cluster = RefCell::new(cluster);

    let must_resolved_ts_advance = |region: &Region| {
        let cluster = cluster.borrow_mut();
        let ts = cluster.store_metas[&region.get_peers()[0].get_store_id()]
            .lock()
            .unwrap()
            .region_read_progress
            .get_resolved_ts(&region.get_id())
            .unwrap();
        let now = Instant::now();
        for peer in region.get_peers() {
            loop {
                let new_ts = cluster.store_metas[&peer.get_store_id()]
                    .lock()
                    .unwrap()
                    .region_read_progress
                    .get_resolved_ts(&region.get_id())
                    .unwrap();
                if new_ts <= ts {
                    if now.saturating_elapsed() > Duration::from_secs(5) {
                        panic!("timeout");
                    }
                    continue;
                }
                break;
            }
        }
    };
    // Now region 1 only has peer (1, 1);
    let (key, value) = (b"k1", b"v1");

    cluster.borrow_mut().must_put(key, value);
    assert_eq!(cluster.borrow_mut().get(key), Some(value.to_vec()));

    // Make sure resolved ts advances.
    let region = cluster.borrow().get_region(&[]);
    must_resolved_ts_advance(&region);

    // Add peer (2, 2) to region 1.
    pd_client.must_add_peer(region.id, new_peer(2, 2));
    must_get_equal(&cluster.borrow().get_engine(2), key, value);

    // Test conf change.
    let region = cluster.borrow().get_region(&[]);
    must_resolved_ts_advance(&region);

    // Test transfer leader.
    let region = cluster.borrow().get_region(&[]);
    cluster
        .borrow_mut()
        .must_transfer_leader(region.get_id(), region.get_peers()[1].clone());
    must_resolved_ts_advance(&region);

    // Test split.
    let split_key = b"k1";
    cluster.borrow_mut().must_split(&region, split_key);
    let left = cluster.borrow().get_region(&[]);
    let right = cluster.borrow().get_region(split_key);
    must_resolved_ts_advance(&left);
    must_resolved_ts_advance(&right);
}