Extract run_test_file from submission.rb

This commit is contained in:
Sebastian Serth
2021-10-17 16:21:13 +02:00
parent 56a1d78793
commit 5f98456276

View File

@ -141,6 +141,27 @@ class Submission < ApplicationRecord
# If prepared_runner raises an error, no Testrun will be created.
prepared_runner do |runner, waiting_duration|
file_scores = collect_files.select(&:teacher_defined_assessment?).map do |file|
output = run_test_file file, runner, waiting_duration
score_file(output, file)
end
end
combine_file_scores(file_scores)
end
def run(file, &block)
run_command = command_for execution_environment.run_command, file.name_with_extension
durations = {}
prepared_runner do |runner, waiting_duration|
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
durations[:waiting_duration] = waiting_duration
rescue Runner::Error => e
e.waiting_duration = waiting_duration
raise
end
durations
end
def run_test_file(file, runner, waiting_duration)
score_command = command_for execution_environment.test_command, file.name_with_extension
output = {file_role: file.role, waiting_for_container_time: waiting_duration}
stdout = +''
@ -168,23 +189,6 @@ class Submission < ApplicationRecord
ensure
output.merge!(stdout: stdout, stderr: stderr)
end
score_file(output, file)
end
end
combine_file_scores(file_scores)
end
def run(file, &block)
run_command = command_for execution_environment.run_command, file.name_with_extension
durations = {}
prepared_runner do |runner, waiting_duration|
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
durations[:waiting_duration] = waiting_duration
rescue Runner::Error => e
e.waiting_duration = waiting_duration
raise
end
durations
end
private