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>
88 lines
3.2 KiB
Ruby
88 lines
3.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
RSpec.describe "Streams::NodeProvisioner cloud" do
|
|
it "registers a cloud node using injected providers" do
|
|
cloud = instance_double(
|
|
Streams::CloudProviders::Hetzner,
|
|
create_node: Streams::CloudProviders::Instance.new(
|
|
id: "99",
|
|
name: "mltv-stream-ingest-01",
|
|
public_ip: "49.13.9.9",
|
|
private_ip: "10.0.0.9",
|
|
status: "running",
|
|
raw: {}
|
|
)
|
|
)
|
|
dns = instance_double(Streams::DnsProviders::Hetzner)
|
|
allow(dns).to receive(:upsert_a)
|
|
|
|
ENV["MEDIAMTX_API_URL"] = "http://mtx-home:9997"
|
|
ENV["MEDIAMTX_RTMP_URL"] = "rtmp://home.example:1935"
|
|
ENV["HLS_PUBLIC_URL"] = "https://home.example/hls"
|
|
ENV["STREAM_CLOUD_DNS_SUFFIX"] = "mltv-stream.net"
|
|
ENV["STREAM_CLOUD_MAX_PUBLISHERS"] = "4"
|
|
ENV["STREAM_CLOUD_PUBLIC_CONTROL"] = "0"
|
|
ENV["STREAM_NODE_READY_TIMEOUT_SECS"] = "0"
|
|
|
|
allow(Streams::NodeHealth).to receive(:promote_if_healthy!).and_return(false)
|
|
|
|
node = Streams::NodeProvisioner.new(cloud: cloud, dns: dns).provision_cloud!
|
|
expect(node.slug).to eq("ingest-01")
|
|
expect(node.role).to eq("cloud")
|
|
expect(node.provider).to eq("hetzner")
|
|
expect(node.status).to eq("provisioning")
|
|
expect(node.hostname).to eq("ingest-01.mltv-stream.net")
|
|
expect(node.rtmp_base_url).to eq("rtmp://ingest-01.mltv-stream.net:1935")
|
|
expect(node.api_base_url).to eq("http://10.0.0.9:9997")
|
|
expect(node.hls_base_url).to eq("https://home.example/hls")
|
|
expect(node.internal_hls_url).to eq("http://10.0.0.9:8888")
|
|
expect(dns).to have_received(:upsert_a).with("ingest-01.mltv-stream.net", "49.13.9.9")
|
|
ensure
|
|
%w[
|
|
MEDIAMTX_API_URL MEDIAMTX_RTMP_URL HLS_PUBLIC_URL
|
|
STREAM_CLOUD_DNS_SUFFIX STREAM_CLOUD_MAX_PUBLISHERS STREAM_CLOUD_PUBLIC_CONTROL
|
|
STREAM_NODE_READY_TIMEOUT_SECS
|
|
].each { |k| ENV.delete(k) }
|
|
end
|
|
|
|
it "marks cloud node ready when MediaMTX answers during wait" do
|
|
cloud = instance_double(
|
|
Streams::CloudProviders::Hetzner,
|
|
create_node: Streams::CloudProviders::Instance.new(
|
|
id: "100",
|
|
name: "mltv-stream-ingest-01",
|
|
public_ip: "49.13.9.9",
|
|
private_ip: "10.0.0.9",
|
|
status: "running",
|
|
raw: {}
|
|
)
|
|
)
|
|
dns = instance_double(Streams::DnsProviders::Hetzner)
|
|
allow(dns).to receive(:upsert_a)
|
|
|
|
ENV["MEDIAMTX_API_URL"] = "http://mtx-home:9997"
|
|
ENV["MEDIAMTX_RTMP_URL"] = "rtmp://home.example:1935"
|
|
ENV["HLS_PUBLIC_URL"] = "https://home.example/hls"
|
|
ENV["STREAM_CLOUD_DNS_SUFFIX"] = "mltv-stream.net"
|
|
ENV["STREAM_CLOUD_PUBLIC_CONTROL"] = "0"
|
|
ENV["STREAM_NODE_READY_TIMEOUT_SECS"] = "5"
|
|
ENV["STREAM_NODE_READY_POLL_SECS"] = "0.01"
|
|
|
|
allow(Streams::NodeHealth).to receive(:promote_if_healthy!) do |node|
|
|
node.update!(status: "ready", last_health_at: Time.current)
|
|
true
|
|
end
|
|
|
|
node = Streams::NodeProvisioner.new(cloud: cloud, dns: dns).provision_cloud!
|
|
expect(node.status).to eq("ready")
|
|
ensure
|
|
%w[
|
|
MEDIAMTX_API_URL MEDIAMTX_RTMP_URL HLS_PUBLIC_URL
|
|
STREAM_CLOUD_DNS_SUFFIX STREAM_CLOUD_PUBLIC_CONTROL
|
|
STREAM_NODE_READY_TIMEOUT_SECS STREAM_NODE_READY_POLL_SECS
|
|
].each { |k| ENV.delete(k) }
|
|
end
|
|
end
|