Re-add test method for SubmissionsController

This commit is contained in:
Sebastian Serth
2021-10-17 16:22:10 +02:00
parent 5f98456276
commit 7285978ea3
2 changed files with 22 additions and 17 deletions

View File

@ -190,23 +190,18 @@ class SubmissionsController < ApplicationController
def statistics; end
# TODO: make this run, but with the test command
# TODO: add this method to the before action for set_submission again
# def test
# hijack do |tubesock|
# unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
# Thread.new do
# EventMachine.run
# ensure
# ActiveRecord::Base.connection_pool.release_connection
# end
# end
# output = @docker_client.execute_test_command(@submission, sanitize_filename)
# # tubesock is the socket to the client
# tubesock.send_data JSON.dump(output)
# tubesock.send_data JSON.dump('cmd' => 'exit')
# end
# end
def test
hijack do |tubesock|
return kill_client_socket(tubesock) if @embed_options[:disable_run]
tubesock.send_data(JSON.dump(@submission.test(@file)))
rescue Runner::Error => e
tubesock.send_data JSON.dump({cmd: :status, status: :container_depleted})
Rails.logger.debug { "Runner error while testing submission #{@submission.id}: #{e.message}" }
ensure
kill_client_socket(tubesock)
end
end
private

View File

@ -161,6 +161,16 @@ class Submission < ApplicationRecord
durations
end
def test(file)
prepared_runner do |runner, waiting_duration|
output = run_test_file file, runner, waiting_duration
score_file output, file
rescue Runner::Error => e
e.waiting_duration = waiting_duration
raise
end
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}