test_river.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """river 0.4 closes every layer surface while no window manager runs: the engine has to wait for one, not crash or quit."""
  2. import time
  3. import pytest
  4. from conftest import changed_fraction
  5. from test_kde import _engine
  6. def _wait_log(log, text, timeout):
  7. deadline = time.monotonic() + timeout
  8. while time.monotonic() < deadline:
  9. if text in log.read_text(errors="replace"):
  10. return True
  11. time.sleep(0.5)
  12. return False
  13. @pytest.mark.parametrize("desktop", ["river"], indirect=True)
  14. def test_waits_for_a_window_manager(desktop, engine, tmp_path):
  15. desktop.stop_window_manager()
  16. before = tmp_path / "before.png"
  17. desktop.shot(before)
  18. log = tmp_path / "engine.log"
  19. process = _engine(desktop, engine, log, desktop.output_names()[0])
  20. try:
  21. assert _wait_log(log, "The compositor closed the wallpaper surface", 30), log.read_text()[-1500:]
  22. assert "No output shows a wallpaper" in log.read_text()
  23. time.sleep(5)
  24. assert process.poll() is None, f"the engine exited with {process.returncode}:\n{log.read_text()[-1500:]}"
  25. desktop.start_window_manager()
  26. assert _wait_log(log, "the compositor took the wallpaper surface again", 45), log.read_text()[-1500:]
  27. after = tmp_path / "after.png"
  28. time.sleep(3)
  29. desktop.shot(after)
  30. fraction = changed_fraction(before, after)
  31. assert fraction >= 0.03, f"{fraction:.0%} of the screen changed once the window manager runs"
  32. assert process.poll() is None
  33. finally:
  34. process.terminate()
  35. process.wait(10)
  36. if desktop.window_manager is None:
  37. desktop.start_window_manager()