()
| 348 | |
| 349 | #[tokio::test] |
| 350 | async fn server_it_works() { |
| 351 | let _ = tracing_subscriber::fmt::try_init(); |
| 352 | |
| 353 | let port = PORT_ALLOC.fetch_add(1, Ordering::SeqCst); |
| 354 | |
| 355 | let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); |
| 356 | let addr = SocketAddr::new(localhost_v4, port); |
| 357 | |
| 358 | let (shutdown_tx, shutdown_rx) = oneshot::channel(); |
| 359 | let cache_path = PathBuf::from(format!( |
| 360 | "{}/redis-test/{}/", |
| 361 | option_env!("CARGO_TARGET_TMPDIR").unwrap_or("/tmp"), |
| 362 | port |
| 363 | )); |
| 364 | let cache_size = 1048576; |
| 365 | |
| 366 | info!(?cache_path); |
| 367 | fs::remove_dir_all(&cache_path); |
| 368 | fs::create_dir_all(&cache_path).unwrap(); |
| 369 | |
| 370 | let mut handle = tokio::spawn(async move { |
| 371 | run_server(cache_size, cache_path, false, addr, shutdown_rx).await; |
| 372 | }); |
| 373 | |
| 374 | // Do the test |
| 375 | let blocking_task = tokio::task::spawn_blocking(move || { |
| 376 | let client = redis::Client::open( |
| 377 | format!("redis://username:password@127.0.0.1:{}/", port).as_str(), |
| 378 | ) |
| 379 | .expect("failed to launch redis client"); |
| 380 | |
| 381 | let mut con = client.get_connection().expect("failed to get connection"); |
| 382 | |
| 383 | let v: InfoDict = cmd("INFO").query(&mut con).expect("Failed to get info"); |
| 384 | |
| 385 | let r = v.get::<u64>("used_memory"); |
| 386 | error!(?r, "used memory"); |
| 387 | |
| 388 | let h: HashMap<String, usize> = cmd("CONFIG") |
| 389 | .arg("GET") |
| 390 | .arg("maxmemory") |
| 391 | .query(&mut con) |
| 392 | .expect("Failed to get config"); |
| 393 | |
| 394 | let mm = h |
| 395 | .get("maxmemory") |
| 396 | .and_then(|&s| if s != 0 { Some(s as u64) } else { None }) |
| 397 | .expect("Failed to get maxmemory"); |
| 398 | |
| 399 | let key = b"test_key"; |
| 400 | let d = b"test_data"; |
| 401 | |
| 402 | let d1: Vec<u8> = cmd("GET") |
| 403 | .arg(key) |
| 404 | .query(&mut con) |
| 405 | .expect("Failed to get key"); |
| 406 | |
| 407 | let d2: Vec<u8> = cmd("SET") |
nothing calls this directly
no test coverage detected