Files
ubicloud/spec/model/github_runner_spec.rb
Furkan Sahin 12dbeb57a1 Update location references with foreign key in the controlplane
We are basically updating the location references everywhere with a
location id and adding the location relationship to the models to be
able to fetch location names when needed.
This also makes the LocationNameConverter model obsolete, so we are
removing it.

Use model id as value for Sequel::Model in resource creation form

Use id of the location as preselected value in Postgres update form
2025-03-23 15:48:19 +01:00

55 lines
2.1 KiB
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe GithubRunner do
subject(:github_runner) {
ins = GithubInstallation.create_with_id(installation_id: 123, name: "test-installation", type: "User")
vm = create_vm(vm_host: create_vm_host, boot_image: "github-ubuntu-2204")
Sshable.create { _1.id = vm.id }
described_class.create_with_id(repository_name: "test-repo", label: "ubicloud", vm_id: vm.id, installation_id: ins.id)
}
it "can log duration when it's from a vm pool" do
pool = VmPool.create_with_id(size: 1, vm_size: "standard-2", location_id: Location::HETZNER_FSN1_ID, boot_image: "github-ubuntu-2204", storage_size_gib: 86)
github_runner.vm.update(pool_id: pool.id)
expect(Clog).to receive(:emit).with("runner_tested").and_call_original
github_runner.log_duration("runner_tested", 10)
end
it "can log duration without a vm" do
github_runner.update(vm_id: nil)
expect(Clog).to receive(:emit).with("runner_tested").and_call_original
github_runner.log_duration("runner_tested", 10)
end
it "provisions a spare runner" do
expect(Prog::Vm::GithubRunner).to receive(:assemble)
.with(github_runner.installation, repository_name: github_runner.repository_name, label: github_runner.label)
.and_return(instance_double(Strand, subject: instance_double(described_class)))
github_runner.provision_spare_runner
end
it "initiates a new health monitor session" do
expect(github_runner.vm.sshable).to receive(:start_fresh_session)
github_runner.init_health_monitor_session
end
it "checks pulse" do
session = {
ssh_session: instance_double(Net::SSH::Connection::Session)
}
pulse = {
reading: "up",
reading_rpt: 5,
reading_chg: Time.now - 30
}
expect(session[:ssh_session]).to receive(:exec!).with("awk '/MemAvailable/ {print $2}' /proc/meminfo").and_return("123\n")
github_runner.check_pulse(session: session, previous_pulse: pulse)
expect(session[:ssh_session]).to receive(:exec!).and_raise Sshable::SshError
github_runner.check_pulse(session: session, previous_pulse: pulse)
end
end