Skip to content

Commit

Permalink
Merge pull request #4087 from OSC/bp-card-fix
Browse files Browse the repository at this point in the history
only show nodes if it's positive (#4074)
  • Loading branch information
johrstrom authored Jan 28, 2025
2 parents 359e2aa + 0599d9b commit 9f5cfb3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
<span class="card-text"> (<%= session.job_id %>)</span>
<div class="float-end">
<%- if session.starting? || session.running? -%>
<%- if num_nodes.positive? -%>
<span class="badge <%= badge_class %> rounded-pill"><%= pluralize(num_nodes, "node") %></span>
<span class="card-text"> | </span>
<%- end -%>
<%- if num_cores.positive? -%>
<span class="badge <%= badge_class %> rounded-pill"><%= pluralize(num_cores, "core") %></span>
<span class="card-text"> | </span>
<%- end -%>
<%- end -%>
<%= status(session) %>
<%- if session.completed? && !session.app.preset? -%>
<span class="card-text"> | </span>
Expand Down
67 changes: 63 additions & 4 deletions apps/dashboard/test/system/batch_connect_sessions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def create_test_file(dir, token: 'sys/bc_paraview', title: 'Paraview')
File.write("#{dir}/#{test_bc_id}", test_data(token: token, title: title).to_json)
end

def stub_scheduler(state)
info = OodCore::Job::Info.new(id: test_job_id, status: state.to_sym)
def stub_scheduler(state, cores: 1, nodes: 1)
info = OodCore::Job::Info.new(
id: test_job_id, status: state.to_sym, procs: cores.to_i,
allocated_nodes: Array.new(nodes.to_i, { name: 'foo', features: [] })
)
OodCore::Job::Adapters::Slurm.any_instance.stubs(:info).returns(info)
end

Expand Down Expand Up @@ -103,7 +106,7 @@ def stub_scheduler(state)
assert_not_nil(card)

header_text = card.find('.h5').text
assert_equal("Jupyter (#{test_job_id})\n0 nodes | 0 cores | Starting", header_text)
assert_equal("Jupyter (#{test_job_id})\n1 node | 1 core | Starting", header_text)
end
end

Expand All @@ -117,10 +120,66 @@ def stub_scheduler(state)
assert_not_nil(card)

header_text = card.find('.h5').text
assert_equal("Paraview (#{test_job_id})\n0 nodes | 0 cores | Starting", header_text)
assert_equal("Paraview (#{test_job_id})\n1 node | 1 core | Starting", header_text)

info_text = card.find("#info_test_div").text
assert_equal('This is a test message for an info view.', info_text)
end
end

test 'running sessions with 0 nodes and cores' do
Dir.mktmpdir do |dir|
create_test_file(dir, token: 'sys/bc_jupyter', title: 'Jupyter')
stub_scheduler(:running, nodes: 0, cores: 0)
visit(batch_connect_sessions_path)

card = find("#id_#{test_bc_id}")
assert_not_nil(card)

header_text = card.find('.h5').text
assert_equal("Jupyter (#{test_job_id})\nStarting", header_text)
end
end

test 'running sessions with 0 nodes and 1 core' do
Dir.mktmpdir do |dir|
create_test_file(dir, token: 'sys/bc_jupyter', title: 'Jupyter')
stub_scheduler(:running, nodes: 0, cores: 1)
visit(batch_connect_sessions_path)

card = find("#id_#{test_bc_id}")
assert_not_nil(card)

header_text = card.find('.h5').text
assert_equal("Jupyter (#{test_job_id})\n1 core | Starting", header_text)
end
end

test 'running sessions with 1 nodes and 0 cores' do
Dir.mktmpdir do |dir|
create_test_file(dir, token: 'sys/bc_jupyter', title: 'Jupyter')
stub_scheduler(:running, nodes: 0, cores: 1)
visit(batch_connect_sessions_path)

card = find("#id_#{test_bc_id}")
assert_not_nil(card)

header_text = card.find('.h5').text
assert_equal("Jupyter (#{test_job_id})\n1 core | Starting", header_text)
end
end

test 'running sessions correctly pluralize nodes and cores' do
Dir.mktmpdir do |dir|
create_test_file(dir, token: 'sys/bc_jupyter', title: 'Jupyter')
stub_scheduler(:running, nodes: 2, cores: 2)
visit(batch_connect_sessions_path)

card = find("#id_#{test_bc_id}")
assert_not_nil(card)

header_text = card.find('.h5').text
assert_equal("Jupyter (#{test_job_id})\n2 nodes | 2 cores | Starting", header_text)
end
end
end

0 comments on commit 9f5cfb3

Please sign in to comment.