Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d117222f
Commit
d117222f
authored
8 years ago
by
uzairr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add timeout in request to xqueue
parent
3c040b93
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
5 deletions
+30
-5
common/lib/capa/capa/xqueue_interface.py
+12
-4
common/lib/xmodule/xmodule/tests/test_capa_module.py
+17
-0
lms/djangoapps/courseware/tests/test_submitting_problems.py
+1
-1
No files found.
common/lib/capa/capa/xqueue_interface.py
View file @
d117222f
...
...
@@ -15,6 +15,8 @@ XQUEUE_METRIC_NAME = 'edxapp.xqueue'
# Wait time for response from Xqueue.
XQUEUE_TIMEOUT
=
35
# seconds
CONNECT_TIMEOUT
=
3.05
# seconds
READ_TIMEOUT
=
10
# seconds
def
make_hashkey
(
seed
):
...
...
@@ -134,12 +136,18 @@ class XQueueInterface(object):
def
_http_post
(
self
,
url
,
data
,
files
=
None
):
try
:
r
=
self
.
session
.
post
(
url
,
data
=
data
,
files
=
files
)
response
=
self
.
session
.
post
(
url
,
data
=
data
,
files
=
files
,
timeout
=
(
CONNECT_TIMEOUT
,
READ_TIMEOUT
)
)
except
requests
.
exceptions
.
ConnectionError
,
err
:
log
.
error
(
err
)
return
(
1
,
'cannot connect to server'
)
if
r
.
status_code
not
in
[
200
]:
return
(
1
,
'unexpected HTTP status code [
%
d]'
%
r
.
status_code
)
except
requests
.
exceptions
.
ReadTimeout
,
err
:
log
.
error
(
err
)
return
(
1
,
'failed to read from the server'
)
if
response
.
status_code
not
in
[
200
]:
return
(
1
,
'unexpected HTTP status code [
%
d]'
%
response
.
status_code
)
return
parse_xreply
(
r
.
text
)
return
parse_xreply
(
r
esponse
.
text
)
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
d117222f
...
...
@@ -8,6 +8,7 @@ Tests of the Capa XModule
import
datetime
import
json
import
random
import
requests
import
os
import
textwrap
import
unittest
...
...
@@ -242,6 +243,22 @@ class CapaModuleTest(unittest.TestCase):
problem
=
CapaFactory
.
create
()
self
.
assertFalse
(
problem
.
answer_available
())
@ddt.data
(
(
requests
.
exceptions
.
ReadTimeout
,
(
1
,
'failed to read from the server'
)),
(
requests
.
exceptions
.
ConnectionError
,
(
1
,
'cannot connect to server'
)),
)
@ddt.unpack
def
test_xqueue_request_exception
(
self
,
exception
,
result
):
"""
Makes sure that platform will raise appropriate exception in case of
connect/read timeout(s) to request to xqueue
"""
xqueue_interface
=
XQueueInterface
(
"http://example.com/xqueue"
,
Mock
())
with
patch
.
object
(
xqueue_interface
.
session
,
'post'
,
side_effect
=
exception
):
# pylint: disable = protected-access
response
=
xqueue_interface
.
_http_post
(
'http://some/fake/url'
,
{})
self
.
assertEqual
(
response
,
result
)
def
test_showanswer_attempted
(
self
):
problem
=
CapaFactory
.
create
(
showanswer
=
'attempted'
)
self
.
assertFalse
(
problem
.
answer_available
())
...
...
This diff is collapsed.
Click to expand it.
lms/djangoapps/courseware/tests/test_submitting_problems.py
View file @
d117222f
...
...
@@ -818,7 +818,7 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems):
self
.
assertEqual
(
name
,
"post"
)
self
.
assertEqual
(
len
(
args
),
1
)
self
.
assertTrue
(
args
[
0
]
.
endswith
(
"/submit/"
))
self
.
assertItemsEqual
(
kwargs
.
keys
(),
[
"files"
,
"data"
])
self
.
assertItemsEqual
(
kwargs
.
keys
(),
[
"files"
,
"data"
,
"timeout"
])
self
.
assertItemsEqual
(
kwargs
[
'files'
]
.
keys
(),
filenames
.
split
())
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment