Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
flame-clmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
flame
flame-clmc
Commits
fafde653
Commit
fafde653
authored
7 years ago
by
Nikolay Stanchev
Browse files
Options
Downloads
Patches
Plain Diff
[ Issue #56 ] - Refactored StreamingSim into fixture
parent
579bd854
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
test/streaming-sim/StreamingSim.py
+37
-7
37 additions, 7 deletions
test/streaming-sim/StreamingSim.py
test/streaming-sim/VerifySimResults.py
+6
-3
6 additions, 3 deletions
test/streaming-sim/VerifySimResults.py
with
43 additions
and
10 deletions
test/streaming-sim/StreamingSim.py
+
37
−
7
View file @
fafde653
...
...
@@ -2,8 +2,9 @@ import LineProtocolGenerator as lp
import
time
import
urllib.parse
import
urllib.request
import
sys
import
pytest
import
random
import
sys
# Simulation parameters
TICK_TIME
=
1
...
...
@@ -17,7 +18,7 @@ AGENT_URL1 = 'http://192.168.50.11:8186'
AGENT_URL2
=
'
http://192.168.50.12:8186
'
# Simulator for services
class
s
im
:
class
S
im
:
def
__init__
(
self
,
influx_url
):
# We don't need this as the db is CLMC metrics
self
.
influx_db
=
'
CLMCMetrics
'
...
...
@@ -185,12 +186,12 @@ class sim:
def
_deleteDB
(
self
):
self
.
_sendInfluxQuery
(
self
.
influx_url
,
'
DROP DATABASE
'
+
self
.
influx_db
)
def
_sendInfluxQuery
(
self
,
url
,
query
):
@staticmethod
def
_sendInfluxQuery
(
url
,
query
):
query
=
urllib
.
parse
.
urlencode
({
'
q
'
:
query
})
query
=
query
.
encode
(
'
ascii
'
)
req
=
urllib
.
request
.
Request
(
url
+
'
/query
'
,
query
)
urllib
.
request
.
urlopen
(
req
)
return
urllib
.
request
.
urlopen
(
req
)
.
read
().
decode
(
"
utf-8
"
).
strip
()
def
_sendInfluxData
(
self
,
url
,
data
):
data
=
data
.
encode
()
...
...
@@ -198,6 +199,35 @@ class sim:
req
=
urllib
.
request
.
Request
(
url
+
'
/write?db=
'
+
self
.
influx_db
,
data
,
header
)
urllib
.
request
.
urlopen
(
req
)
simulator
=
sim
(
INFLUX_DB_URL
)
simulator
.
run
(
SIMULATION_TIME_SEC
)
@pytest.fixture
def
run_simulation_fixture
():
global
INFLUX_DB_URL
global
SIMULATION_TIME_SEC
dbs
=
Sim
.
_sendInfluxQuery
(
INFLUX_DB_URL
,
"
SHOW DATABASES
"
)
if
"
CLMCMetrics
"
not
in
dbs
:
simulator
=
Sim
(
INFLUX_DB_URL
)
simulator
.
run
(
SIMULATION_TIME_SEC
)
import
time
time
.
sleep
(
10
)
def
run_simulation
(
generate
=
True
):
global
INFLUX_DB_URL
global
SIMULATION_TIME_SEC
simulator
=
Sim
(
INFLUX_DB_URL
)
if
generate
:
simulator
.
run
(
SIMULATION_TIME_SEC
)
else
:
simulator
.
_deleteDB
()
if
__name__
==
"
__main__
"
:
option
=
True
if
len
(
sys
.
argv
)
>
1
:
option
=
str
(
sys
.
argv
[
1
])
!=
"
-c
"
run_simulation
(
generate
=
option
)
This diff is collapsed.
Click to expand it.
test/streaming-sim/VerifySimResults.py
+
6
−
3
View file @
fafde653
...
...
@@ -2,7 +2,9 @@ from urllib.parse import urlencode
from
urllib.request
import
Request
,
urlopen
from
json
import
loads
from
os.path
import
join
,
dirname
import
pytest
from
pytest
import
fixture
from
StreamingSim
import
run_simulation_fixture
class
TestSimulation
(
object
):
...
...
@@ -10,10 +12,11 @@ class TestSimulation(object):
A
'
testing
'
class used to group all the tests related to the simulation data
"""
def
test_simulation
(
self
,
queries_to_test
):
def
test_simulation
(
self
,
run_simulation_fixture
,
queries_to_test
):
"""
This is the entry point of the test. This method will be found and executed when the module is ran using pytest
:param run_simulation: the imported fixture to use to generate the testing data - the return value of the fixture is not needed in this case
:param queries_to_test: the fixture to use - returns a JSON object represented as a python dictionary
"""
...
...
@@ -63,7 +66,7 @@ class TestSimulation(object):
return
result
.
read
().
decode
(
"
utf-8
"
).
strip
()
@staticmethod
@
pytest.
fixture
@fixture
def
queries_to_test
():
"""
A pytest fixture used to read the queries, which would be tested, from a JSON file
...
...
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