Evita doppi ffmpeg tra host: stop solo sull'owner, ensure con requeue a capacità piena e coda Sidekiq youtube_relay isolata. Co-authored-by: Cursor <cursoragent@cursor.com>
67 lines
2.4 KiB
Ruby
67 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
RSpec.describe Streams::YoutubeRelay do
|
|
describe ".youtube_ffmpeg_args (private)" do
|
|
def args(mode, url)
|
|
described_class.send(:youtube_ffmpeg_args, [mode, url], "rtmps://a.rtmps.youtube.com/live2/key")
|
|
end
|
|
|
|
it "remuxes RTMP with video and audio copy (no AAC re-encode)" do
|
|
cmd = args(:rtmp, "rtmp://mediamtx:1935/live/match_x")
|
|
expect(cmd).to include("-c:v", "copy", "-c:a", "copy", "-f", "flv")
|
|
expect(cmd).not_to include("aac")
|
|
expect(cmd.join(" ")).not_to include("-b:a")
|
|
end
|
|
|
|
it "remuxes HLS with AAC bitstream filter for FLV" do
|
|
cmd = args(:hls, "http://mediamtx:8888/live/match_x/index.m3u8")
|
|
expect(cmd).to include("-c:v", "copy", "-c:a", "copy", "-bsf:a", "aac_adtstoasc", "-f", "flv")
|
|
expect(cmd).not_to include("-b:a")
|
|
end
|
|
end
|
|
|
|
describe "multi-host sticky stop/capacity" do
|
|
let(:redis) { Redis.new(url: ENV.fetch("REDIS_URL", "redis://redis:6379/0")) }
|
|
let(:session_id) { SecureRandom.uuid }
|
|
|
|
before do
|
|
allow(described_class).to receive(:worker?).and_return(true)
|
|
allow(described_class).to receive(:worker_id).and_return("worker-a")
|
|
allow(described_class).to receive(:max_concurrent).and_return(1)
|
|
redis.flushdb
|
|
end
|
|
|
|
def session_double
|
|
instance_double(
|
|
StreamSession,
|
|
id: session_id,
|
|
platform: "youtube",
|
|
terminal?: false,
|
|
stream_key: "yt-key",
|
|
status: "live"
|
|
)
|
|
end
|
|
|
|
it "does not stop ffmpeg owned by another worker" do
|
|
redis.set(format(Streams::YoutubeRelay::OWNER_KEY, session_id), "worker-b", ex: 3600)
|
|
redis.set(format(Streams::YoutubeRelay::REDIS_KEY, session_id), "12345", ex: 3600)
|
|
|
|
expect(described_class.stop_on_worker!(session_double)).to eq(:wrong_host)
|
|
expect(redis.get(format(Streams::YoutubeRelay::OWNER_KEY, session_id))).to eq("worker-b")
|
|
end
|
|
|
|
it "requeues ensure when at capacity" do
|
|
other_id = SecureRandom.uuid
|
|
redis.sadd(format(Streams::YoutubeRelay::OWNED_SET, "worker-a"), other_id)
|
|
allow(described_class).to receive(:intake_available?).and_return(true)
|
|
expect(YoutubeRelayEnsureJob).to receive(:set).with(hash_including(wait: 5.seconds, queue: :youtube_relay)).and_return(
|
|
double(perform_later: true)
|
|
)
|
|
|
|
expect(described_class.ensure_on_worker!(session_double)).to eq(:at_capacity)
|
|
end
|
|
end
|
|
end
|