diff --git a/common/lib/capa/capa/templates/matlabinput.html b/common/lib/capa/capa/templates/matlabinput.html index 9e093bac43..ee8cc62c58 100644 --- a/common/lib/capa/capa/templates/matlabinput.html +++ b/common/lib/capa/capa/templates/matlabinput.html @@ -49,9 +49,8 @@ %endif - diff --git a/common/lib/xmodule/xmodule/js/fixtures/matlabinput_problem.html b/common/lib/xmodule/xmodule/js/fixtures/matlabinput_problem.html new file mode 100644 index 0000000000..5dad82c727 --- /dev/null +++ b/common/lib/xmodule/xmodule/js/fixtures/matlabinput_problem.html @@ -0,0 +1,43 @@ +
+
+
+ +

+

+
+
+ + +
+ + processing + + + + +

processing

+
+ + + +
+ Submitted. As soon as a response is returned, this message will be replaced by that feedback. +
+
+ +
+ +
+ +
+ + +
+
+
+
+ + + +
+
diff --git a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee index a8d881c6e6..170f0b3826 100644 --- a/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/capa/display_spec.coffee @@ -628,3 +628,31 @@ describe 'Problem', -> it 'check_save_waitfor should return false', -> $(@problem.inputs[0]).data('waitfor', ->) expect(@problem.check_save_waitfor()).toEqual(false) + + describe 'Submitting an xqueue-graded problem', -> + matlabinput_html = readFixtures('matlabinput_problem.html') + + beforeEach -> + spyOn($, 'postWithPrefix').andCallFake (url, callback) -> + callback html: matlabinput_html + jasmine.Clock.useMock() + @problem = new Problem($('.xblock-student_view')) + spyOn(@problem, 'poll').andCallThrough() + @problem.render(matlabinput_html) + + it 'check that we stop polling after a fixed amount of time', -> + expect(@problem.poll).not.toHaveBeenCalled() + jasmine.Clock.tick(1) + time_steps = [1000, 2000, 4000, 8000, 16000, 32000] + num_calls = 1 + for time_step in time_steps + do (time_step) => + jasmine.Clock.tick(time_step) + expect(@problem.poll.callCount).toEqual(num_calls) + num_calls += 1 + + # jump the next step and verify that we are not still continuing to poll + jasmine.Clock.tick(64000) + expect(@problem.poll.callCount).toEqual(6) + + expect($('.capa_alert').text()).toEqual("The grading process is still running. Refresh the page to see updates.") diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index da817c1254..43de29bfe4 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -98,19 +98,11 @@ class @Problem if @num_queued_items > 0 if window.queuePollerID # Only one poller 'thread' per Problem window.clearTimeout(window.queuePollerID) - queuelen = @get_queuelen() - window.queuePollerID = window.setTimeout(@poll, queuelen*10) + window.queuePollerID = window.setTimeout( + => @poll(1000), + 1000) - # Retrieves the minimum queue length of all queued items - get_queuelen: => - minlen = Infinity - @queued_items.each (index, qitem) -> - len = parseInt($.text(qitem)) - if len < minlen - minlen = len - return minlen - - poll: => + poll: (prev_timeout) => $.postWithPrefix "#{@url}/problem_get", (response) => # If queueing status changed, then render @new_queued_items = $(response.html).find(".xqueue") @@ -125,8 +117,16 @@ class @Problem @forceUpdate response delete window.queuePollerID else - # TODO: Some logic to dynamically adjust polling rate based on queuelen - window.queuePollerID = window.setTimeout(@poll, 1000) + new_timeout = prev_timeout * 2 + # if the timeout is greather than 1 minute + if new_timeout >= 60000 + delete window.queuePollerID + @gentle_alert gettext("The grading process is still running. Refresh the page to see updates.") + else + window.queuePollerID = window.setTimeout( + => @poll(new_timeout), + new_timeout + ) # Use this if you want to make an ajax call on the input type object