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: server.rs
    path of file: ./repos/webapp.rs/backend/tests
    
    the code of the file until where you have to start completion: use anyhow::{format_err, Result};
use lazy_static::lazy_static;
use reqwest::blocking::Client;
use serde_json::from_slice;
use std::{sync::Mutex, thread, time::Duration};
use url::Url;
use webapp::{
    config::Config,
    protocol::{model::Session, request, response},
    API_URL_LOGIN_CREDENTIALS, API_URL_LOGIN_SESSION, API_URL_LOGOUT, CONFIG_FILENAME,
};
use webapp_backend::Server;

lazy_static! {
    static ref PORT: Mutex<u16> = Mutex::new(30000);
}

fn get_config() -> Result<Config> {
    Ok(Config::from_file(&format!("../{}", CONFIG_FILENAME))?)
}

fn get_next_port() -> u16 {
    let mut port = PORT.lock().unwrap();
    *port += 1;
    *port
}

pub fn create_testserver() -> Result<Url> {
    // Prepare the configurati
    
pub fn create_testserver() -> Result<Url> {
    // Prepare the configuration
    let mut config = get_config()?;

    // Set the test configuration
    let mut url = Url::parse(&config.server.url)?;
    url.set_port(Some(get_next_port()))
        .map_err(|_| format_err!("Unable to set server port"))?;
    config.server.url = url.to_string();
    config.server.redirect_from = vec![];

    // Start the server
    let config_clone = config.clone();
    thread::spawn(move || Server::from_config(&config_clone).unwrap().start());

    // Wait until the server is up
    loop {
        if let Ok(res) = Client::new().get(url.as_str()).send() {
            if res.status().is_success() {
                break;
            }
        }
        thread::sleep(Duration::from_secs(1))
    }

    // Return the server url
    Ok(url)
}