Extract run_test_file from submission.rb
This commit is contained in:
@ -141,6 +141,27 @@ class Submission < ApplicationRecord
|
|||||||
# If prepared_runner raises an error, no Testrun will be created.
|
# If prepared_runner raises an error, no Testrun will be created.
|
||||||
prepared_runner do |runner, waiting_duration|
|
prepared_runner do |runner, waiting_duration|
|
||||||
file_scores = collect_files.select(&:teacher_defined_assessment?).map do |file|
|
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
|
score_command = command_for execution_environment.test_command, file.name_with_extension
|
||||||
output = {file_role: file.role, waiting_for_container_time: waiting_duration}
|
output = {file_role: file.role, waiting_for_container_time: waiting_duration}
|
||||||
stdout = +''
|
stdout = +''
|
||||||
@ -168,23 +189,6 @@ class Submission < ApplicationRecord
|
|||||||
ensure
|
ensure
|
||||||
output.merge!(stdout: stdout, stderr: stderr)
|
output.merge!(stdout: stdout, stderr: stderr)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Reference in New Issue
Block a user