Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions test/services/autoscale_servers_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AutoscaleServersServiceTest < ActiveSupport::TestCase
let(:signup_minimum) { Service::MIN_INSTANCES_FOR_SIGNUP_OPENING }
let(:now) { Time.zone.local(2026, 6, 1, 12, 0, 0) }

# (a few dozen attendees is plenty to push the target above the minimum, and each one is a database row)
def convention_with_attendees(count, **attributes)
convention = create(:convention, **attributes)
create_list(:user_con_profile, count, convention:)
Expand All @@ -27,7 +28,7 @@ def open_signups(convention, at:, maximum_event_signups: "unlimited")

it "grows with the number of attendees, never less than the minimum for a signup opening" do
small = Service.scaling_target_for_signup_opening(convention_with_attendees(4))
large = Service.scaling_target_for_signup_opening(convention_with_attendees(200))
large = Service.scaling_target_for_signup_opening(convention_with_attendees(40))

assert_operator small, :>=, signup_minimum
assert_operator large, :>, small
Expand Down Expand Up @@ -112,7 +113,7 @@ def throttle(time)
end

it "scales up for a convention with a signup round about to open" do
convention = convention_with_attendees(300)
convention = convention_with_attendees(40)
open_signups(convention, at: now + 30.minutes)

target = Service.scaling_target_for(now)
Expand All @@ -123,23 +124,26 @@ def throttle(time)
end

it "rounds up to a whole number of instances" do
convention = convention_with_attendees(300)
convention = convention_with_attendees(40)
open_signups(convention, at: now + 30.minutes)
exact = Service.scaling_target_for_signup_opening(convention)

assert_equal [exact.ceil, max_instances].min, Service.scaling_target_for(now)
end

it "never goes above the maximum" do
convention = convention_with_attendees(5000)
convention = create(:convention)
open_signups(convention, at: now + 30.minutes)

assert_equal max_instances, Service.scaling_target_for(now)
# (as if there were thousands of attendees, without creating them)
Service.stub(:scaling_target_for_signup_opening, 500.0) do
assert_equal max_instances, Service.scaling_target_for(now)
end
end

it "uses the busiest of several conventions" do
small = convention_with_attendees(5)
large = convention_with_attendees(300)
large = convention_with_attendees(40)
open_signups(small, at: now + 30.minutes)
open_signups(large, at: now + 30.minutes)

Expand All @@ -149,30 +153,30 @@ def throttle(time)
end

it "ignores signup rounds that open further ahead than the lookahead" do
convention = convention_with_attendees(300)
convention = convention_with_attendees(40)
open_signups(convention, at: now + Service::SIGNUP_OPENING_LOOKAHEAD_TIME + 1.hour)

assert_equal min_instances, Service.scaling_target_for(now)
end

it "ignores signup rounds that opened further back than the lookback" do
convention = convention_with_attendees(300)
convention = convention_with_attendees(40)
open_signups(convention, at: now - Service::SIGNUP_OPENING_LOOKBACK_TIME - 1.hour)

assert_equal min_instances, Service.scaling_target_for(now)
end

it "ignores rounds that do not let anyone sign up" do
convention = convention_with_attendees(300)
convention = convention_with_attendees(40)
open_signups(convention, at: now + 30.minutes, maximum_event_signups: "not_now")
other = convention_with_attendees(300)
other = convention_with_attendees(40)
open_signups(other, at: now + 30.minutes, maximum_event_signups: "not_yet")

assert_equal min_instances, Service.scaling_target_for(now)
end

it "ignores conventions where signups need to be moderated" do
convention = convention_with_attendees(300, signup_mode: "moderated")
convention = convention_with_attendees(40, signup_mode: "moderated")
open_signups(convention, at: now + 30.minutes)

assert_equal min_instances, Service.scaling_target_for(now)
Expand Down
Loading