Fix 17 previously failing specs

This commit is contained in:
Felix Auringer
2021-06-08 12:36:49 +02:00
committed by Sebastian Serth
parent 0280c0282e
commit cf58be97ee
8 changed files with 66 additions and 71 deletions

View File

@ -31,38 +31,27 @@ module SubmissionScoring
LinterCheckRun.create_from(testrun, assessment)
assessment = assessor.translate_linter(assessment, I18n.locale)
# replace file name with hint if linter is not used for grading. Refactor!
filename = t('exercises.implement.not_graded') if file.weight.zero?
end
# replace file name with hint if linter is not used for grading. Refactor!
filename = t('exercises.implement.not_graded', locale: :de) if file.weight.zero?
end
output.merge!(assessment)
output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight)
end
private :collect_test_results
def execute_test_file(file, submission)
# TODO: replace DockerClient here
DockerClient.new(execution_environment: file.context.execution_environment).execute_test_command(submission,
file.name_with_extension)
end
private :execute_test_file
def feedback_message(_file, output)
# TODO: why did we comment out set_locale and render_markdown?
set_locale
# TODO: make this a controller concern again to bring the locales nearer to the view
def feedback_message(file, output)
if output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_test'
I18n.t('exercises.implement.default_test_feedback')
elsif output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_linter'
I18n.t('exercises.implement.default_linter_feedback')
else
render_markdown(file.feedback_message)
# render_markdown(file.feedback_message)
file.feedback_message
end
end
def score_submission(outputs)
# outputs = collect_test_results(submission)
submission = self
score = 0.0
if outputs.present?

View File

@ -4,7 +4,6 @@ class ExercisesController < ApplicationController
include CommonBehavior
include Lti
include SubmissionParameters
include SubmissionScoring
include TimeHelper
before_action :handle_file_uploads, only: %i[create update]
@ -533,7 +532,7 @@ working_time_accumulated: working_time_accumulated})
def submit
@submission = Submission.create(submission_params)
score_submission(@submission)
@submission.calculate_score
if @submission.user.external_user? && lti_outcome_service?(@submission.exercise_id, @submission.user.id)
transmit_lti_score
else

View File

@ -2,7 +2,6 @@
class RemoteEvaluationController < ApplicationController
include RemoteEvaluationParameters
include SubmissionScoring
include Lti
skip_after_action :verify_authorized
@ -63,7 +62,7 @@ status: 202}
validation_token = remote_evaluation_params[:validation_token]
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(validation_token: validation_token))
@submission = Submission.create(build_submission_params(cause, remote_evaluation_mapping))
score_submission(@submission)
@submission.calculate_score
else
# TODO: better output
# TODO: check token expired?

View File

@ -1,8 +1,6 @@
# frozen_string_literal: true
class RequestForCommentsController < ApplicationController
include SubmissionScoring
before_action :require_user!
before_action :set_request_for_comment, only: %i[show mark_as_solved set_thank_you_note]
before_action :set_study_group_grouping,
@ -121,7 +119,7 @@ class RequestForCommentsController < ApplicationController
if @request_for_comment.save
# create thread here and execute tests. A run is triggered from the frontend and does not need to be handled here.
Thread.new do
score_submission(@request_for_comment.submission)
@request_for_comment.submission.calculate_score
ensure
ActiveRecord::Base.connection_pool.release_connection
end

View File

@ -5,7 +5,6 @@ class SubmissionsController < ApplicationController
include CommonBehavior
include Lti
include SubmissionParameters
include SubmissionScoring
include Tubesock::Hijack
before_action :set_submission,
@ -237,25 +236,21 @@ class SubmissionsController < ApplicationController
end
def score
Thread.new do
hijack do |tubesock|
return kill_socket(tubesock) if @embed_options[:disable_run]
hijack do |tubesock|
return kill_socket(tubesock) if @embed_options[:disable_run]
tubesock.send_data(@submission.calculate_score)
# To enable hints when scoring a submission, uncomment the next line:
# send_hints(tubesock, StructuredError.where(submission: @submission))
rescue Runner::Error::ExecutionTimeout => e
tubesock.send_data JSON.dump({cmd: :status, status: :timeout})
Rails.logger.debug { "Running a submission failed: #{e.message}" }
rescue Runner::Error => e
tubesock.send_data JSON.dump({cmd: :status, status: :container_depleted})
Rails.logger.debug { "Runner error while scoring a submission: #{e.message}" }
ensure
tubesock.send_data JSON.dump({cmd: :exit})
tubesock.close
end
tubesock.send_data(@submission.calculate_score)
# To enable hints when scoring a submission, uncomment the next line:
# send_hints(tubesock, StructuredError.where(submission: @submission))
rescue Runner::Error::ExecutionTimeout => e
tubesock.send_data JSON.dump({cmd: :status, status: :timeout})
Rails.logger.debug { "Running a submission failed: #{e.message}" }
rescue Runner::Error => e
tubesock.send_data JSON.dump({cmd: :status, status: :container_depleted})
Rails.logger.debug { "Runner error while scoring a submission: #{e.message}" }
ensure
ActiveRecord::Base.connection_pool.release_connection
tubesock.send_data JSON.dump({cmd: :exit})
tubesock.close
end
end