Commit aff794fe authored by OPNA2608's avatar OPNA2608
Browse files

nixosTests.lomiri-gallery-app: Cache media in thumbnailer ahead-of-time, retry until successful

parent 23274a2a
Loading
Loading
Loading
Loading
+38 −4
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ let
              systemPackages =
                with pkgs;
                [
                  glib # Poke thumbnailer to process media via gdbus
                  mpv # URI dispatching for video support
                  xdotool # mouse movement
                ]
@@ -78,7 +79,14 @@ let
              };
            };

            i18n.supportedLocales = [ "all" ];
            # Allow us to start thumbnailer ahead-of-time, hopefully let thumbnails get processed in peace
            systemd.user.services."dbus-com.lomiri.Thumbnailer" = {
              serviceConfig = {
                Type = "dbus";
                BusName = "com.lomiri.Thumbnailer";
                ExecStart = "${pkgs.lomiri.lomiri-thumbnailer}/libexec/lomiri-thumbnailer/thumbnailer-service";
              };
            };

            fonts = {
              packages = with pkgs; [
@@ -97,6 +105,34 @@ let
            machine.succeed("mkdir /root/${builtins.dirOf file}")
            machine.succeed("cp -vr /etc/${imageDataDir}/${file} /root/${builtins.dirOf file}")

            # Start thumbnailer, wait for idle shutdown
            machine.systemctl("start dbus-com.lomiri.Thumbnailer", "root")
            machine.wait_until_succeeds(
                "env XDG_RUNTIME_DIR=/run/user/0 "
                + "systemctl --user is-active dbus-com.lomiri.Thumbnailer"
            )
            machine.wait_for_console_text("thumbnail cache:")

            # Request thumbnail processing, get initial thumbnail image into cache
            # This can randomly take abit longer, just run it until it succeeds
            # Touch file to invalidate failure cache
            machine.wait_until_succeeds(
                "touch '/root/${file}' && "
                + "env XDG_RUNTIME_DIR=/run/user/0 "
                + "gdbus call -e "
                + "-d com.lomiri.Thumbnailer -o /com/lomiri/Thumbnailer "
                + "-m com.lomiri.Thumbnailer.GetThumbnail "
                + "'/root/${file}' "
                # Same size as source, to reduce processing - we're very close to hitting 20s on slow hardware here
                + "'@(ii) (500,500)'"
            )

            machine.wait_for_console_text("Idle timeout reached")
            machine.wait_until_fails(
                "env XDG_RUNTIME_DIR=/run/user/0 "
                + "systemctl --user is-active dbus-com.lomiri.Thumbnailer"
            )

            with subtest("lomiri gallery finds files"):
                machine.succeed("lomiri-gallery-app >&2 &")
                machine.wait_for_console_text("qq= AlbumsOverview") # logged when album page actually gets loaded
@@ -243,15 +279,13 @@ in
          machine.sleep(2)

          machine.wait_for_text("${imageLabel}") # make sure thumbnail processing worked
          machine.screenshot("lomiri-gallery_mp4_thumbnail")

          machine.succeed("xdotool mousemove 510 380 click 1") # dispatch to system's video handler
          machine.wait_until_succeeds("pgrep -u root -f mpv") # wait for video to start
          machine.sleep(10)
          machine.succeed("pgrep -u root -f mpv") # should still be playing
          machine.screenshot("lomiri-gallery_mp4_dispatch")

          machine.send_key("q")
          machine.wait_until_fails("pgrep mpv") # wait for video to stop
    '';
  }
  {