Remove all occurrences of server-sent events
This commit is contained in:
@ -315,22 +315,6 @@ class SubmissionsController < ApplicationController
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
def with_server_sent_events
|
|
||||||
response.headers['Content-Type'] = 'text/event-stream'
|
|
||||||
server_sent_event = SSE.new(response.stream)
|
|
||||||
server_sent_event.write(nil, event: 'start')
|
|
||||||
yield(server_sent_event) if block_given?
|
|
||||||
server_sent_event.write({code: 200}, event: 'close')
|
|
||||||
rescue StandardError => e
|
|
||||||
Sentry.capture_exception(e)
|
|
||||||
logger.error(e.message)
|
|
||||||
logger.error(e.backtrace.join("\n"))
|
|
||||||
server_sent_event.write({code: 500}, event: 'close')
|
|
||||||
ensure
|
|
||||||
server_sent_event.close
|
|
||||||
end
|
|
||||||
private :with_server_sent_events
|
|
||||||
|
|
||||||
def create_remote_evaluation_mapping
|
def create_remote_evaluation_mapping
|
||||||
user = @submission.user
|
user = @submission.user
|
||||||
exercise_id = @submission.exercise_id
|
exercise_id = @submission.exercise_id
|
||||||
|
@ -154,10 +154,6 @@ describe SubmissionsController do
|
|||||||
let(:filename) { submission.collect_files.detect(&:main_file?).name_with_extension }
|
let(:filename) { submission.collect_files.detect(&:main_file?).name_with_extension }
|
||||||
let(:perform_request) { get :run, params: {filename: filename, id: submission.id} }
|
let(:perform_request) { get :run, params: {filename: filename, id: submission.id} }
|
||||||
|
|
||||||
before do
|
|
||||||
allow_any_instance_of(ActionController::Live::SSE).to receive(:write).at_least(3).times
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when no errors occur during execution' do
|
context 'when no errors occur during execution' do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(DockerClient).to receive(:execute_run_command).with(submission, filename).and_return({})
|
allow_any_instance_of(DockerClient).to receive(:execute_run_command).with(submission, filename).and_return({})
|
||||||
@ -229,54 +225,4 @@ describe SubmissionsController do
|
|||||||
|
|
||||||
pending('todo')
|
pending('todo')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#with_server_sent_events' do
|
|
||||||
let(:response) { ActionDispatch::TestResponse.new }
|
|
||||||
|
|
||||||
before { allow(controller).to receive(:response).and_return(response) }
|
|
||||||
|
|
||||||
context 'when no error occurs' do
|
|
||||||
after { controller.send(:with_server_sent_events) }
|
|
||||||
|
|
||||||
it 'uses server-sent events' do
|
|
||||||
expect(ActionController::Live::SSE).to receive(:new).and_call_original
|
|
||||||
end
|
|
||||||
|
|
||||||
it "writes a 'start' event" do
|
|
||||||
allow_any_instance_of(ActionController::Live::SSE).to receive(:write)
|
|
||||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:write).with(nil, event: 'start')
|
|
||||||
end
|
|
||||||
|
|
||||||
it "writes a 'close' event" do
|
|
||||||
allow_any_instance_of(ActionController::Live::SSE).to receive(:write)
|
|
||||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:write).with({code: 200}, event: 'close')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'closes the stream' do
|
|
||||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:close).and_call_original
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when an error occurs' do
|
|
||||||
after { controller.send(:with_server_sent_events) { raise } }
|
|
||||||
|
|
||||||
it 'uses server-sent events' do
|
|
||||||
expect(ActionController::Live::SSE).to receive(:new).and_call_original
|
|
||||||
end
|
|
||||||
|
|
||||||
it "writes a 'start' event" do
|
|
||||||
allow_any_instance_of(ActionController::Live::SSE).to receive(:write)
|
|
||||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:write).with(nil, event: 'start')
|
|
||||||
end
|
|
||||||
|
|
||||||
it "writes a 'close' event" do
|
|
||||||
allow_any_instance_of(ActionController::Live::SSE).to receive(:write)
|
|
||||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:write).with({code: 500}, event: 'close')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'closes the stream' do
|
|
||||||
expect_any_instance_of(ActionController::Live::SSE).to receive(:close).and_call_original
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -364,7 +364,7 @@ describe DockerClient, docker: true do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'provides the command to be executed as input' do
|
it 'provides the command to be executed as input' do
|
||||||
pending('we are currently not using any input and for output server send events instead of attach.')
|
pending('we are currently not using attach but rather exec.')
|
||||||
expect(container).to receive(:attach).with(stdin: kind_of(StringIO))
|
expect(container).to receive(:attach).with(stdin: kind_of(StringIO))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user