Skip to content

Commit

Permalink
Stub out evaluate_in_container.
Browse files Browse the repository at this point in the history
Return the expected array of values during testing instead of spinning
up a Docker container for actual evaluation.
Add a short sleep to facilitate timeout testing.

Remove `wait_for_evaluation` stub.

Fix ProgrammingEvaluationService specs.
Use a non-zero timeout as Ruby timeout treats 0 as infinite.
Remove create_evaluation tests.
  • Loading branch information
fonglh committed Jun 1, 2017
1 parent bd513f9 commit 410f7da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,13 @@
context 'when the evaluation times out' do
it 'raises a Timeout::Error' do
expect do
# Pass in a non-zero timeout as Ruby's Timeout treats 0 as infinite.
subject.execute(course, Coursemology::Polyglot::Language::Python::Python2Point7.instance,
64, 5.seconds, File.join(Rails.root, 'spec', 'fixtures', 'course',
'programming_question_template.zip'), 0.seconds)
'programming_question_template.zip'),
0.1.seconds)
end.to raise_error(Timeout::Error)
end
end

describe '#create_evaluation' do
subject do
Course::Assessment::ProgrammingEvaluationService.
new(course, Coursemology::Polyglot::Language::Python::Python2Point7.instance, 64,
5.seconds, File.join(Rails.root, 'spec', 'fixtures', 'course',
'programming_question_template.zip'), 5.seconds)
end

it 'creates the package for the evaluator to download' do
evaluation = subject.send(:create_evaluation)

# Remove the leading / because Pathname treats it as an absolute path.
expect(Rails.public_path + evaluation.package_path[1..-1]).to exist
end

it 'successfully creates the evaluation' do
evaluation = subject.send(:create_evaluation)
expect(evaluation).to be_persisted
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,13 @@
module Course::Assessment::StubbedProgrammingEvaluationService
private

def wait_for_evaluation(evaluation)
thread = Thread.new do
ActiveRecord::Base.connection_pool.with_connection do
ActsAsTenant.without_tenant do
populate_mock_result(evaluation)
end
end
end
thread.abort_on_exception = true
def evaluate_in_container
attributes = FactoryGirl.attributes_for(:course_assessment_programming_evaluation, :completed).
slice(:stdout, :stderr, :test_report, :exit_code)
# For timeout testing
sleep(0.2)

super
end

# Populates the evaluation with fake results.
#
# @param [Course::Assessment::ProgrammingEvaluation] evaluation The evaluation to populate
# mock results for.
def populate_mock_result(evaluation)
evaluation = Course::Assessment::ProgrammingEvaluation.find(evaluation.id)
attributes = FactoryGirl.
attributes_for(:course_assessment_programming_evaluation, :completed).
slice(:stdout, :stderr, :test_report, :exit_code)
evaluation.assign!(User.system)
evaluation.assign_attributes(attributes)
evaluation.complete!
evaluation.save!
[attributes[:stdout], attributes[:stderr], attributes[:test_report], attributes[:exit_code]]
end
end

Expand Down

0 comments on commit 410f7da

Please sign in to comment.