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
Mar 09, 2017
by
uzairr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add timeout in request to xqueue
parent
3c040b93
Show 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'
...
@@ -15,6 +15,8 @@ XQUEUE_METRIC_NAME = 'edxapp.xqueue'
# Wait time for response from Xqueue.
# Wait time for response from Xqueue.
XQUEUE_TIMEOUT
=
35
# seconds
XQUEUE_TIMEOUT
=
35
# seconds
CONNECT_TIMEOUT
=
3.05
# seconds
READ_TIMEOUT
=
10
# seconds
def
make_hashkey
(
seed
):
def
make_hashkey
(
seed
):
...
@@ -134,12 +136,18 @@ class XQueueInterface(object):
...
@@ -134,12 +136,18 @@ class XQueueInterface(object):
def
_http_post
(
self
,
url
,
data
,
files
=
None
):
def
_http_post
(
self
,
url
,
data
,
files
=
None
):
try
:
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
:
except
requests
.
exceptions
.
ConnectionError
,
err
:
log
.
error
(
err
)
log
.
error
(
err
)
return
(
1
,
'cannot connect to server'
)
return
(
1
,
'cannot connect to server'
)
if
r
.
status_code
not
in
[
200
]:
except
requests
.
exceptions
.
ReadTimeout
,
err
:
return
(
1
,
'unexpected HTTP status code [
%
d]'
%
r
.
status_code
)
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
)
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
d117222f
...
@@ -8,6 +8,7 @@ Tests of the Capa XModule
...
@@ -8,6 +8,7 @@ Tests of the Capa XModule
import
datetime
import
datetime
import
json
import
json
import
random
import
random
import
requests
import
os
import
os
import
textwrap
import
textwrap
import
unittest
import
unittest
...
@@ -242,6 +243,22 @@ class CapaModuleTest(unittest.TestCase):
...
@@ -242,6 +243,22 @@ class CapaModuleTest(unittest.TestCase):
problem
=
CapaFactory
.
create
()
problem
=
CapaFactory
.
create
()
self
.
assertFalse
(
problem
.
answer_available
())
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
):
def
test_showanswer_attempted
(
self
):
problem
=
CapaFactory
.
create
(
showanswer
=
'attempted'
)
problem
=
CapaFactory
.
create
(
showanswer
=
'attempted'
)
self
.
assertFalse
(
problem
.
answer_available
())
self
.
assertFalse
(
problem
.
answer_available
())
...
...
lms/djangoapps/courseware/tests/test_submitting_problems.py
View file @
d117222f
...
@@ -818,7 +818,7 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems):
...
@@ -818,7 +818,7 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems):
self
.
assertEqual
(
name
,
"post"
)
self
.
assertEqual
(
name
,
"post"
)
self
.
assertEqual
(
len
(
args
),
1
)
self
.
assertEqual
(
len
(
args
),
1
)
self
.
assertTrue
(
args
[
0
]
.
endswith
(
"/submit/"
))
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
())
self
.
assertItemsEqual
(
kwargs
[
'files'
]
.
keys
(),
filenames
.
split
())
...
...
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