I nodi cloud restano in provisioning finché :9997 risponde; retry su create_path e 503 retryable se l’ingest è ancora irraggiungibile. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
2.0 KiB
Ruby
51 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
RSpec.describe Mediamtx::Client do
|
|
describe "#create_path" do
|
|
let(:session) do
|
|
user = User.create!(email: "mtx-#{SecureRandom.hex(4)}@example.com", name: "M", password: "Password123", role: "coach")
|
|
club = Club.create!(name: "MtxClub-#{SecureRandom.hex(3)}", sport: "volleyball")
|
|
team = club.teams.create!(name: "T", sport: "volleyball", slug: "mtx-#{SecureRandom.hex(4)}")
|
|
match = team.matches.create!(opponent_name: "X", scheduled_at: 1.hour.from_now)
|
|
StreamSession.create!(match: match, user: user, platform: "matchlivetv", status: "idle")
|
|
end
|
|
|
|
it "retries Faraday connection failures then succeeds" do
|
|
ENV["MEDIAMTX_CREATE_RETRIES"] = "3"
|
|
ENV["MEDIAMTX_CREATE_RETRY_BASE_SECS"] = "0"
|
|
|
|
client = described_class.new(base_url: "http://mtx.test:9997")
|
|
conn = instance_double(Faraday::Connection)
|
|
client.instance_variable_set(:@conn, conn)
|
|
|
|
fail_once = Faraday::ConnectionFailed.new("Connection refused")
|
|
ok = instance_double(Faraday::Response, success?: true, status: 200, body: {})
|
|
|
|
expect(conn).to receive(:post).once.and_raise(fail_once)
|
|
expect(conn).to receive(:post).once.and_return(ok)
|
|
|
|
expect(client.create_path(session)).to eq(true)
|
|
ensure
|
|
ENV.delete("MEDIAMTX_CREATE_RETRIES")
|
|
ENV.delete("MEDIAMTX_CREATE_RETRY_BASE_SECS")
|
|
end
|
|
|
|
it "raises after exhausting connection retries" do
|
|
ENV["MEDIAMTX_CREATE_RETRIES"] = "2"
|
|
ENV["MEDIAMTX_CREATE_RETRY_BASE_SECS"] = "0"
|
|
|
|
client = described_class.new(base_url: "http://mtx.test:9997")
|
|
conn = instance_double(Faraday::Connection)
|
|
client.instance_variable_set(:@conn, conn)
|
|
allow(conn).to receive(:post).and_raise(Faraday::ConnectionFailed.new("Connection refused"))
|
|
|
|
expect { client.create_path(session) }.to raise_error(Faraday::ConnectionFailed)
|
|
ensure
|
|
ENV.delete("MEDIAMTX_CREATE_RETRIES")
|
|
ENV.delete("MEDIAMTX_CREATE_RETRY_BASE_SECS")
|
|
end
|
|
end
|
|
end
|