agent: fix test for the debug console
Fix test for the debug console.
-// Copyright (c) 2019 Ant Financial
+// Copyright (c) 2021 Ant Group
// Copyright (c) 2021 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
@@ -232,23 +232,27 @@ async fn run_debug_console_serial(shell: String, fd: RawFd) -> Result<()> {
Ok(())
}
-// BUG: FIXME:
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
+ use tokio::sync::watch;
- #[test]
- fn test_setup_debug_console_no_shells() {
+ #[tokio::test]
+ async fn test_setup_debug_console_no_shells() {
+ {
// Guarantee no shells have been added
// (required to avoid racing with
// test_setup_debug_console_invalid_shell()).
let shells_ref = SHELLS.clone();
let mut shells = shells_ref.lock().unwrap();
shells.clear();
+ }
+
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_eq!(
@@ -257,8 +261,9 @@ mod tests {
);
}
- #[test]
- fn test_setup_debug_console_invalid_shell() {
+ #[tokio::test]
+ async fn test_setup_debug_console_invalid_shell() {
+ {
let shells_ref = SHELLS.clone();
let mut shells = shells_ref.lock().unwrap();
@@ -273,9 +278,12 @@ mod tests {
.to_string();
shells.push(shell);
+ }
+
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_eq!(
