YaLTeR / wl-clipboard-rs

A safe Rust crate for working with the Wayland clipboard.
Apache License 2.0
255 stars 17 forks source link

Make tests robust #1

Closed YaLTeR closed 1 year ago

YaLTeR commented 5 years ago

The way the tests are currently set up is each test brings up a Wayland server and runs the tested code in the second thread, while the main thread sleeps and dispatches messages on the server side the required number of times: https://github.com/YaLTeR/wl-clipboard-rs/blob/b29b92416496677494ad7ddde6a0c6dde437e6ef/src/tests/paste.rs#L180-L188 This is not very robust because depending on the thread scheduling the (arbitrarily chosen) 100 ms delay might not be enough for the second thread to do its chunk of work and send data over the Wayland socket.

It should be possible to change this to be predictable. Most of the crate code (except the last loop in copy()) currently does its communication via EventQueue::sync_roundtrip() which might help here too. For the reference, see how the test roundtrip() function is set up in the wayland-rs tests: https://github.com/Smithay/wayland-rs/blob/11c8875a7b59aa24020eff48b0de82abba705af1/tests/helpers/mod.rs#L84-L113