Skip to content

Commit 6121840

Browse files
emilkabey79
andauthored
Add test for UI wakeup (#7422)
### What * Part of #7378 ### Issues found * #7425 * emilk/egui#5114 * #7427 ## How to test #### 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) ## Tested ### Web * [x] ✅ Browser alt-tabbed * [x] ❌ Web background tab * Has never _properly_ worked. Is blocked on emilk/egui#5112 * It catches up when we switch back to the tab though ### Linux * [x] ✅X11 alt-tabbed * [x] ✅ X11 minimized * [x] ✅ Wayland alt-tabbed * [x] ❌ Wayland minimized (Hyprland placed on non-visible workspace) * [x] ✅ X-Wayland alt-tabbed * [x] ✅ X-Wayland minimized (Hyprland placed on non-visible workspace) ### Mac * [x] ✅ Native alt-tabbed * [x] ✅ Native minimized ### Windows * [x] ✅ Native alt-tabbed * [x] ✅ Native minimized ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7422?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7422?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7422) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`. --------- Co-authored-by: Antoine Beyeler <49431240+abey79@users.noreply.github.com>
1 parent a48e1b9 commit 6121840

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

Cargo.lock

+10
Original file line numberDiff line numberDiff line change
@@ -7111,6 +7111,16 @@ dependencies = [
71117111
"rerun",
71127112
]
71137113

7114+
[[package]]
7115+
name = "test_ui_wakeup"
7116+
version = "0.19.0-alpha.1+dev"
7117+
dependencies = [
7118+
"anyhow",
7119+
"clap",
7120+
"re_log",
7121+
"rerun",
7122+
]
7123+
71147124
[[package]]
71157125
name = "thiserror"
71167126
version = "1.0.63"

crates/viewer/re_viewer/src/app.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,8 @@ impl App {
10341034
let start = web_time::Instant::now();
10351035

10361036
while let Some((channel_source, msg)) = self.rx.try_recv() {
1037+
re_log::trace!("Received a message from {channel_source:?}"); // Used by `test_ui_wakeup` test app!
1038+
10371039
let msg = match msg.payload {
10381040
re_smart_channel::SmartMessagePayload::Msg(msg) => msg,
10391041

tests/rust/test_ui_wakeup/Cargo.toml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "test_ui_wakeup"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
publish = false
8+
9+
[lints]
10+
workspace = true
11+
12+
[dependencies]
13+
re_log = { workspace = true, features = ["setup"] }
14+
rerun = { path = "../../../crates/top/rerun", features = [
15+
"clap",
16+
"web_viewer",
17+
] }
18+
19+
anyhow.workspace = true
20+
clap = { workspace = true, features = ["derive"] }

tests/rust/test_ui_wakeup/src/main.rs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//! Test that the Rerun Viewer UI wakes up as new messages arrive,
2+
//! even if the viewer is hidden.
3+
//!
4+
//! ## Test setup - build the viewer
5+
//! * `pixi run rerun-build`
6+
//! * `pixi run rerun-build-web`
7+
//!
8+
//! ## Test matrix
9+
//! * Run `cargo r -p test_ui_wakeup` and test:
10+
//! * That the viewer wakes up in the background when it's alt-tabbed
11+
//! * That the viewer wakes up when minimized (it should log "Received a message from…")
12+
//! * Run `cargo r -p test_ui_wakeup -- --serve` and test:
13+
//! * The viewer wakes up when browser is alt-tabbed away
14+
//! * Switch to a different browser tab, send a few messages, switch back. The messages should be there
15+
//! (this is not a conclusive test, as the messages might have been received on tab select)
16+
17+
use std::io::Read as _;
18+
19+
#[derive(Debug, clap::Parser)]
20+
#[clap(author, version, about)]
21+
struct Args {
22+
#[command(flatten)]
23+
rerun: rerun::clap::RerunArgs,
24+
}
25+
26+
fn main() -> anyhow::Result<()> {
27+
re_log::setup_logging();
28+
29+
use clap::Parser as _;
30+
let args = Args::parse();
31+
32+
// This is so that re_viewer logs incoming messages:
33+
let rust_log = "info,re_viewer=trace";
34+
eprintln!("Setting RUST_LOG={rust_log}");
35+
std::env::set_var("RUST_LOG", rust_log);
36+
37+
println!("Starting Viewer…");
38+
let (rec, _serve_guard) = args.rerun.init("rerun_example_ui_wakeup")?;
39+
40+
// Wait out some log spam from the viewer starting:
41+
std::thread::sleep(std::time::Duration::from_secs(1));
42+
43+
println!("Now put the viewer in the background (alt-tab, minimize, put in background tab, etc");
44+
45+
for i in 0.. {
46+
println!("Sending message number {i}…");
47+
rec.log(
48+
"Text",
49+
&rerun::TextDocument::new(format!("This is message number {i}")),
50+
)?;
51+
println!("Press ENTER to send more data to the viewer");
52+
53+
wait_from_enter();
54+
}
55+
56+
Ok(())
57+
}
58+
59+
fn wait_from_enter() {
60+
let _ = std::io::stdin()
61+
.read(&mut [0u8])
62+
.expect("Failed to read from stdin");
63+
}

0 commit comments

Comments
 (0)