Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for UI wakeup #7422

Merged
merged 10 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7111,6 +7111,16 @@ dependencies = [
"rerun",
]

[[package]]
name = "test_ui_wakeup"
version = "0.19.0-alpha.1+dev"
dependencies = [
"anyhow",
"clap",
"re_log",
"rerun",
]

[[package]]
name = "thiserror"
version = "1.0.63"
Expand Down
2 changes: 2 additions & 0 deletions crates/viewer/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,8 @@ impl App {
let start = web_time::Instant::now();

while let Some((channel_source, msg)) = self.rx.try_recv() {
re_log::trace!("Received a message from {channel_source:?}"); // Used by `test_ui_wakeup` test app!

let msg = match msg.payload {
re_smart_channel::SmartMessagePayload::Msg(msg) => msg,

Expand Down
20 changes: 20 additions & 0 deletions tests/rust/test_ui_wakeup/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "test_ui_wakeup"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish = false

[lints]
workspace = true

[dependencies]
re_log = { workspace = true, features = ["setup"] }
rerun = { path = "../../../crates/top/rerun", features = [
"clap",
"web_viewer",
] }

anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
63 changes: 63 additions & 0 deletions tests/rust/test_ui_wakeup/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! Test that the Rerun Viewer UI wakes up as new messages arrive,
//! even if the viewer is hidden.
//!
//! ## Test setup - build the viewer
//! * `pixi run rerun-build`
//! * `pixi run rerun-build-web`
//!
//! ## Test matrix
//! * Run `cargo r -p test_ui_wakeup` and test:
//! * That the viewer wakes up in the background when it's alt-tabbed
//! * That the viewer wakes up when minimized (it should log "Received a message from…")
//! * Run `cargo r -p test_ui_wakeup -- --serve` and test:
//! * The viewer wakes up when browser is alt-tabbed away
//! * Switch to a different browser tab, send a few messages, switch back. The messages should be there
//! (this is not a conclusive test, as the messages might have been received on tab select)

use std::io::Read as _;

#[derive(Debug, clap::Parser)]
#[clap(author, version, about)]
struct Args {
#[command(flatten)]
rerun: rerun::clap::RerunArgs,
}

fn main() -> anyhow::Result<()> {
re_log::setup_logging();

use clap::Parser as _;
let args = Args::parse();

// This is so that re_viewer logs incoming messages:
let rust_log = "info,re_viewer=trace";
eprintln!("Setting RUST_LOG={rust_log}");
std::env::set_var("RUST_LOG", rust_log);

println!("Starting Viewer…");
let (rec, _serve_guard) = args.rerun.init("rerun_example_ui_wakeup")?;

// Wait out some log spam from the viewer starting:
std::thread::sleep(std::time::Duration::from_secs(1));

println!("Now put the viewer in the background (alt-tab, minimize, put in background tab, etc");

for i in 0.. {
println!("Sending message number {i}…");
rec.log(
"Text",
&rerun::TextDocument::new(format!("This is message number {i}")),
)?;
println!("Press ENTER to send more data to the viewer");

wait_from_enter();
}

Ok(())
}

fn wait_from_enter() {
let _ = std::io::stdin()
.read(&mut [0u8])
.expect("Failed to read from stdin");
}
Loading