Skip to content

Commit

Permalink
Add test for UI wakeup (#7422)
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
  • Loading branch information
emilk and abey79 authored Sep 18, 2024
1 parent a48e1b9 commit 6121840
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
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");
}

0 comments on commit 6121840

Please sign in to comment.