ubicloud/spec/prog/resolve_globally_blocked_dnsnames_spec.rb
Jeremy Evans 4dc5c281c9 Support running specs with frozen environment
This allows for running the specs with a frozen environment that
should closely match the production environment.

This adds the following rake tasks:

* coverage: Runs specs in serial with coverage
* frozen_spec: Runs specs in serial in frozen environment
* frozen_pspec: Runs specs in parallel in frozen environment

It changes the default rake task to run both the coverage and
frozen_spec tasks.  It also changes the GitHub CI workflow
to use the default rake task.

When specs are run in the frozen environment they call
clover_freeze before running the specs, after loading all
other code.

There are currently 56 specs that do not work in the frozen
environment.  They are skipped by including the skip_if_frozen
method in each spec.
2024-10-27 13:25:30 -07:00

34 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative "../model/spec_helper"
require "socket"
RSpec.describe Prog::ResolveGloballyBlockedDnsnames do
subject(:rgbd) {
described_class.new(Strand.new(prog: "ResolveGloballyBlockedDnsnames", label: "wait"))
}
let(:globally_blocked_dnsname) { GloballyBlockedDnsname.create_with_id(dns_name: "example.com", last_check_at: "2023-10-19 19:27:47 +0000") }
describe "#wait" do
before do
globally_blocked_dnsname
end
it "resolves dnsnames to ip addresses and updates records" do
skip_if_frozen
expect(Socket).to receive(:getaddrinfo).with("example.com", nil).and_return([[nil, nil, nil, "1.1.1.1"], [nil, nil, nil, "2a00:1450:400e:811::200e"], [nil, nil, nil, "1.1.1.1"]])
expect(Time).to receive(:now).and_return(Time.new("2023-10-19 23:27:47 +0000")).at_least(:once)
expect { rgbd.wait }.to nap(60 * 60)
expect(globally_blocked_dnsname.reload.ip_list.map(&:to_s).sort).to eq(["1.1.1.1", "2a00:1450:400e:811::200e"])
end
it "skips if socket fails" do
skip_if_frozen
expect(Socket).to receive(:getaddrinfo).with("example.com", nil).and_raise(SocketError)
expect { rgbd.wait }.to nap(60 * 60)
expect(globally_blocked_dnsname.reload.ip_list).to be_nil
end
end
end