nixos/tests/mediamtx: make more robust, reformat

We're sleeping now until the timeout of the receive service is reached
to check for its state since it might fail until the stream is
available.
This commit is contained in:
Franz Pletz 2024-05-13 23:47:34 +02:00
parent a8a3cf536e
commit 8e7ebfe4f5
No known key found for this signature in database
GPG Key ID: 846FDED7792617B4

View File

@ -1,57 +1,60 @@
import ./make-test-python.nix ({ pkgs, lib, ...} : import ./make-test-python.nix (
{ pkgs, lib, ... }:
{ {
name = "mediamtx"; name = "mediamtx";
meta.maintainers = with lib.maintainers; [ fpletz ]; meta.maintainers = with lib.maintainers; [ fpletz ];
nodes = { nodes = {
machine = { config, ... }: { machine = {
services.mediamtx = { services.mediamtx = {
enable = true; enable = true;
settings = { settings = {
metrics = true; metrics = true;
paths.all.source = "publisher"; paths.all.source = "publisher";
};
}; };
};
systemd.services.rtmp-publish = { systemd.services.rtmp-publish = {
description = "Publish an RTMP stream to mediamtx"; description = "Publish an RTMP stream to mediamtx";
after = [ "mediamtx.service" ]; after = [ "mediamtx.service" ];
bindsTo = [ "mediamtx.service" ]; bindsTo = [ "mediamtx.service" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
DynamicUser = true; DynamicUser = true;
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "1s"; RestartSec = "1s";
TimeoutStartSec = "10s"; TimeoutStartSec = "10s";
ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -re -f lavfi -i smptebars=size=800x600:rate=10 -c libx264 -f flv rtmp://localhost:1935/test"; ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -re -f lavfi -i smptebars=size=800x600:rate=10 -c libx264 -f flv rtmp://localhost:1935/test";
};
}; };
};
systemd.services.rtmp-receive = { systemd.services.rtmp-receive = {
description = "Receive an RTMP stream from mediamtx"; description = "Receive an RTMP stream from mediamtx";
after = [ "rtmp-publish.service" ]; after = [ "rtmp-publish.service" ];
bindsTo = [ "rtmp-publish.service" ]; bindsTo = [ "rtmp-publish.service" ];
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
DynamicUser = true; DynamicUser = true;
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "1s"; RestartSec = "1s";
TimeoutStartSec = "10s"; TimeoutStartSec = "10s";
ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -y -re -i rtmp://localhost:1935/test -f flv /dev/null"; ExecStart = "${lib.getBin pkgs.ffmpeg-headless}/bin/ffmpeg -y -re -i rtmp://localhost:1935/test -f flv /dev/null";
};
}; };
}; };
}; };
};
testScript = '' testScript = ''
start_all() start_all()
machine.wait_for_unit("mediamtx.service") machine.wait_for_unit("mediamtx.service")
machine.wait_for_unit("rtmp-publish.service") machine.wait_for_unit("rtmp-publish.service")
machine.wait_for_unit("rtmp-receive.service") machine.sleep(10)
machine.wait_for_open_port(9998) machine.wait_for_unit("rtmp-receive.service")
machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"publish\".*1$'") machine.wait_for_open_port(9998)
machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"read\".*1$'") machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"publish\".*1$'")
''; machine.succeed("curl http://localhost:9998/metrics | grep '^rtmp_conns.*state=\"read\".*1$'")
}) '';
}
)