Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
fractalis
Manage
Activity
Members
Labels
Plan
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fractalis
fractalis
Commits
d4b8ca52
Commit
d4b8ca52
authored
8 years ago
by
Sascha Herzinger
Browse files
Options
Downloads
Patches
Plain Diff
introducing sync. option for analytics GET and making tests more robust
parent
ee951b4a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fractalis/analytics/controllers.py
+5
-2
5 additions, 2 deletions
fractalis/analytics/controllers.py
tests/test_analytics.py
+10
-9
10 additions, 9 deletions
tests/test_analytics.py
with
15 additions
and
11 deletions
fractalis/analytics/controllers.py
+
5
−
2
View file @
d4b8ca52
...
...
@@ -51,9 +51,11 @@ def get_job_details(task_id):
if
task_id
not
in
session
[
'
tasks
'
]:
# access control
return
jsonify
({
'
error
'
:
"
No matching task found.
"
}),
404
async_result
=
celery
.
AsyncResult
(
task_id
)
if
request
.
args
.
get
(
'
wait
'
)
and
request
.
args
.
get
(
'
wait
'
)
==
'
1
'
:
async_result
.
get
(
propagate
=
False
)
# wait for results
state
=
async_result
.
state
result
=
async_result
.
result
if
isinstance
(
result
,
Exception
):
if
isinstance
(
result
,
Exception
):
# Exception -> str
result
=
"
{}: {}
"
.
format
(
type
(
result
).
__name__
,
str
(
result
))
return
jsonify
({
'
status
'
:
state
,
'
result
'
:
result
}),
200
...
...
@@ -64,6 +66,7 @@ def cancel_job(task_id):
task_id
=
str
(
task_id
)
if
task_id
not
in
session
[
'
tasks
'
]:
# Access control
return
jsonify
({
'
error
'
:
"
No matching task found.
"
}),
404
celery
.
control
.
revoke
(
task_id
,
terminate
=
True
)
# possibly dangerous: http://stackoverflow.com/a/29627549
celery
.
control
.
revoke
(
task_id
,
terminate
=
True
,
signal
=
'
SIGUSR1
'
,
wait
=
True
)
session
[
'
tasks
'
].
remove
(
task_id
)
return
jsonify
({
'
task_id
'
:
task_id
}),
200
This diff is collapsed.
Click to expand it.
tests/test_analytics.py
+
10
−
9
View file @
d4b8ca52
"""
This module tests the analytics controller.
"""
"""
This module tests the analytics controller module.
"""
import
uuid
import
time
import
flask
import
pytest
from
fractalis.celery
import
app
as
celery
class
TestAnalytics
(
object
):
...
...
@@ -103,9 +106,8 @@ class TestAnalytics(object):
task
=
'
test.add
'
,
args
=
{
'
a
'
:
1
,
'
b
'
:
2
}
)))
time
.
sleep
(
1
)
body
=
flask
.
json
.
loads
(
rv
.
get_data
())
new_url
=
'
/analytics/{}
'
.
format
(
body
[
'
task_id
'
])
new_url
=
'
/analytics/{}
?wait=1
'
.
format
(
body
[
'
task_id
'
])
new_response
=
app
.
get
(
new_url
)
new_body
=
flask
.
json
.
loads
(
new_response
.
get_data
())
assert
new_body
[
'
result
'
]
==
3
...
...
@@ -117,7 +119,7 @@ class TestAnalytics(object):
)))
time
.
sleep
(
1
)
body
=
flask
.
json
.
loads
(
rv
.
get_data
())
new_url
=
'
/analytics/{}
'
.
format
(
body
[
'
task_id
'
])
new_url
=
'
/analytics/{}
?wait=0
'
.
format
(
body
[
'
task_id
'
])
new_response
=
app
.
get
(
new_url
)
new_body
=
flask
.
json
.
loads
(
new_response
.
get_data
())
assert
not
new_body
[
'
result
'
]
...
...
@@ -128,25 +130,24 @@ class TestAnalytics(object):
task
=
'
test.div
'
,
args
=
{
'
a
'
:
2
,
'
b
'
:
0
}
)))
time
.
sleep
(
1
)
body
=
flask
.
json
.
loads
(
rv
.
get_data
())
new_url
=
'
/analytics/{}
'
.
format
(
body
[
'
task_id
'
])
new_url
=
'
/analytics/{}
?wait=1
'
.
format
(
body
[
'
task_id
'
])
new_response
=
app
.
get
(
new_url
)
new_body
=
flask
.
json
.
loads
(
new_response
.
get_data
())
assert
new_body
[
'
status
'
]
==
'
FAILURE
'
assert
'
ZeroDivisionError
'
in
new_body
[
'
result
'
]
def
test_404_if_status_non_existing_resource
(
self
,
app
):
assert
app
.
get
(
'
/analytics/{}
'
.
format
(
uuid
.
uuid4
())).
status_code
==
404
assert
app
.
get
(
'
/analytics/{}?wait=1
'
.
format
(
uuid
.
uuid4
())
).
status_code
==
404
def
test_404_if_status_without_auth
(
self
,
app
):
rv
=
app
.
post
(
'
/analytics
'
,
data
=
flask
.
json
.
dumps
(
dict
(
task
=
'
test.do_nothing
'
,
args
=
{
'
seconds
'
:
4
}
)))
time
.
sleep
(
1
)
body
=
flask
.
json
.
loads
(
rv
.
get_data
())
new_url
=
'
/analytics/{}
'
.
format
(
body
[
'
task_id
'
])
new_url
=
'
/analytics/{}
?wait=0
'
.
format
(
body
[
'
task_id
'
])
with
app
.
session_transaction
()
as
sess
:
sess
[
'
tasks
'
]
=
[]
assert
app
.
get
(
new_url
).
status_code
==
404
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment