agent: fix test for the debug console

Fix test for the debug console.

Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
Tim Zhang 2021-04-07 21:03:10 +08:00
parent 790332575b
commit 24b0703fda

View File

@ -1,4 +1,4 @@
// Copyright (c) 2019 Ant Financial // Copyright (c) 2021 Ant Group
// Copyright (c) 2021 Intel Corporation // Copyright (c) 2021 Intel Corporation
// //
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
@ -232,23 +232,27 @@ async fn run_debug_console_serial(shell: String, fd: RawFd) -> Result<()> {
Ok(()) Ok(())
} }
// BUG: FIXME:
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use tempfile::tempdir; use tempfile::tempdir;
use tokio::sync::watch;
#[test] #[tokio::test]
fn test_setup_debug_console_no_shells() { async fn test_setup_debug_console_no_shells() {
{
// Guarantee no shells have been added // Guarantee no shells have been added
// (required to avoid racing with // (required to avoid racing with
// test_setup_debug_console_invalid_shell()). // test_setup_debug_console_invalid_shell()).
let shells_ref = SHELLS.clone(); let shells_ref = SHELLS.clone();
let mut shells = shells_ref.lock().unwrap(); let mut shells = shells_ref.lock().unwrap();
shells.clear(); shells.clear();
}
let logger = slog_scope::logger(); let logger = slog_scope::logger();
let result = setup_debug_console(&logger, shells.to_vec(), 0); let (_, rx) = watch::channel(true);
let result = debug_console_handler(logger, 0, rx).await;
assert!(result.is_err()); assert!(result.is_err());
assert_eq!( assert_eq!(
@ -257,8 +261,9 @@ mod tests {
); );
} }
#[test] #[tokio::test]
fn test_setup_debug_console_invalid_shell() { async fn test_setup_debug_console_invalid_shell() {
{
let shells_ref = SHELLS.clone(); let shells_ref = SHELLS.clone();
let mut shells = shells_ref.lock().unwrap(); let mut shells = shells_ref.lock().unwrap();
@ -273,9 +278,12 @@ mod tests {
.to_string(); .to_string();
shells.push(shell); shells.push(shell);
}
let logger = slog_scope::logger(); let logger = slog_scope::logger();
let result = setup_debug_console(&logger, shells.to_vec(), 0); let (_, rx) = watch::channel(true);
let result = debug_console_handler(logger, 0, rx).await;
assert!(result.is_err()); assert!(result.is_err());
assert_eq!( assert_eq!(