Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
core
tarantool
Commits
e049d314
Commit
e049d314
authored
11 years ago
by
Eugine Blikh
Browse files
Options
Downloads
Patches
Plain Diff
Moving Test related code to parent class Test
parent
63010d95
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/lib/tarantool_server.py
+27
-56
27 additions, 56 deletions
test/lib/tarantool_server.py
test/lib/test_suite.py
+21
-5
21 additions, 5 deletions
test/lib/test_suite.py
test/lib/unittest_server.py
+9
-69
9 additions, 69 deletions
test/lib/unittest_server.py
with
57 additions
and
130 deletions
test/lib/tarantool_server.py
+
27
−
56
View file @
e049d314
...
@@ -49,48 +49,8 @@ def create_tmpfs_vardir(vardir):
...
@@ -49,48 +49,8 @@ def create_tmpfs_vardir(vardir):
os
.
symlink
(
os
.
path
.
join
(
"
/dev/shm
"
,
vardir
),
vardir
)
os
.
symlink
(
os
.
path
.
join
(
"
/dev/shm
"
,
vardir
),
vardir
)
class
FuncTest
(
Test
):
class
FuncTest
(
Test
):
def
__init__
(
self
,
name
,
args
,
suite_ini
):
Test
.
__init__
(
self
,
name
,
args
,
suite_ini
)
self
.
name
=
name
self
.
result
=
name
.
replace
(
"
.test
"
,
"
.result
"
)
self
.
skip_cond
=
name
.
replace
(
"
.test
"
,
"
.skipcond
"
)
self
.
tmp_result
=
os
.
path
.
join
(
self
.
args
.
vardir
,
os
.
path
.
basename
(
self
.
result
))
self
.
reject
=
"
{0}/test/{1}
"
.
format
(
self
.
args
.
builddir
,
name
.
replace
(
"
.test
"
,
"
.reject
"
))
def
execute
(
self
,
server
):
def
execute
(
self
,
server
):
diagnostics
=
"
unknown
"
execfile
(
self
.
name
,
dict
(
locals
(),
**
server
.
__dict__
))
builddir
=
self
.
args
.
builddir
save_stdout
=
sys
.
stdout
try
:
self
.
skip
=
0
if
os
.
path
.
exists
(
self
.
skip_cond
):
sys
.
stdout
=
FilteredStream
(
self
.
tmp_result
)
stdout_fileno
=
sys
.
stdout
.
stream
.
fileno
()
execfile
(
self
.
skip_cond
,
dict
(
locals
(),
**
server
.
__dict__
))
sys
.
stdout
.
close
()
sys
.
stdout
=
save_stdout
if
not
self
.
skip
:
sys
.
stdout
=
FilteredStream
(
self
.
tmp_result
)
stdout_fileno
=
sys
.
stdout
.
stream
.
fileno
()
execfile
(
self
.
name
,
dict
(
locals
(),
**
server
.
__dict__
))
self
.
is_executed_ok
=
True
except
Exception
as
e
:
traceback
.
print_exc
(
e
)
diagnostics
=
str
(
e
)
finally
:
if
sys
.
stdout
and
sys
.
stdout
!=
save_stdout
:
sys
.
stdout
.
close
()
sys
.
stdout
=
save_stdout
;
self
.
is_executed
=
True
def
__repr__
(
self
):
return
str
([
self
.
name
,
self
.
result
,
self
.
skip_cond
,
self
.
tmp_result
,
self
.
reject
])
__str__
=
__repr__
class
TarantoolConfigFile
:
class
TarantoolConfigFile
:
"""
ConfigParser can
'
t read files without sections, work it around
"""
"""
ConfigParser can
'
t read files without sections, work it around
"""
...
@@ -140,10 +100,11 @@ class TarantoolServer(Server):
...
@@ -140,10 +100,11 @@ class TarantoolServer(Server):
def
find_exe
(
self
,
builddir
,
silent
=
True
):
def
find_exe
(
self
,
builddir
,
silent
=
True
):
"
Locate server executable in the build dir or in the PATH.
"
"
Locate server executable in the build dir or in the PATH.
"
self
.
builddir
=
builddir
builddir
=
os
.
path
.
join
(
builddir
,
"
src/box
"
)
builddir
=
os
.
path
.
join
(
builddir
,
"
src/box
"
)
path
=
builddir
+
os
.
pathsep
+
os
.
environ
[
"
PATH
"
]
path
=
builddir
+
os
.
pathsep
+
os
.
environ
[
"
PATH
"
]
if
not
silent
:
if
not
silent
:
print
"
Looking for server binary in {0} ...
"
.
format
(
path
)
print
"
Looking for server binary in {0} ...
"
.
format
(
path
)
for
dir
in
path
.
split
(
os
.
pathsep
):
for
dir
in
path
.
split
(
os
.
pathsep
):
exe
=
os
.
path
.
join
(
dir
,
self
.
default_bin_name
)
exe
=
os
.
path
.
join
(
dir
,
self
.
default_bin_name
)
if
os
.
access
(
exe
,
os
.
X_OK
):
if
os
.
access
(
exe
,
os
.
X_OK
):
...
@@ -179,30 +140,36 @@ class TarantoolServer(Server):
...
@@ -179,30 +140,36 @@ class TarantoolServer(Server):
else
:
else
:
os
.
makedirs
(
self
.
vardir
)
os
.
makedirs
(
self
.
vardir
)
shutil
.
copy
(
self
.
config
,
os
.
path
.
join
(
self
.
vardir
,
shutil
.
copy
(
self
.
config
,
self
.
default_config_name
))
os
.
path
.
join
(
self
.
vardir
,
self
.
default_config_name
))
shutil
.
copy
(
self
.
valgrind_sup
,
shutil
.
copy
(
self
.
valgrind_sup
,
os
.
path
.
join
(
self
.
vardir
,
self
.
default_suppression_name
))
os
.
path
.
join
(
self
.
vardir
,
self
.
default_suppression_name
))
var_init_lua
=
os
.
path
.
join
(
self
.
vardir
,
self
.
default_init_lua_name
)
var_init_lua
=
os
.
path
.
join
(
self
.
vardir
,
self
.
default_init_lua_name
)
if
self
.
init_lua
!=
None
:
if
self
.
init_lua
!=
None
:
if
os
.
path
.
exists
(
var_init_lua
):
os
.
remove
(
var_init_lua
)
shutil
.
copy
(
self
.
init_lua
,
var_init_lua
)
shutil
.
copy
(
self
.
init_lua
,
var_init_lua
)
elif
os
.
path
.
exists
(
var_init_lua
):
# We must delete old init.lua if it exists
os
.
remove
(
var_init_lua
)
def
configure
(
self
,
config
):
def
configure
(
self
,
config
):
def
get_option
(
config
,
section
,
key
):
value
=
config
.
get
(
section
,
key
)
if
value
.
isdigit
():
value
=
int
(
value
)
return
value
config
.
get
()
self
.
config
=
os
.
path
.
abspath
(
config
)
self
.
config
=
os
.
path
.
abspath
(
config
)
# now read the server config, we need some properties from it
# now read the server config, we need some properties from it
with
open
(
self
.
config
)
as
fp
:
with
open
(
self
.
config
)
as
fp
:
dummy_section_name
=
"
tarantool
"
dummy_section_name
=
"
tarantool
"
config
=
ConfigParser
.
ConfigParser
()
config
=
ConfigParser
.
ConfigParser
()
config
.
readfp
(
TarantoolConfigFile
(
fp
,
dummy_section_name
))
config
.
readfp
(
TarantoolConfigFile
(
fp
,
dummy_section_name
))
self
.
pidfile
=
config
.
get
(
dummy_section_name
,
"
pid_file
"
)
self
.
pidfile
=
get_option
(
config
,
dummy_section_name
,
"
pid_file
"
)
self
.
primary_port
=
self
.
get_option
_int
(
config
,
dummy_section_name
,
"
primary_port
"
)
self
.
primary_port
=
get_option
(
config
,
dummy_section_name
,
"
primary_port
"
)
self
.
admin_port
=
self
.
get_option
_int
(
config
,
dummy_section_name
,
"
admin_port
"
)
self
.
admin_port
=
get_option
(
config
,
dummy_section_name
,
"
admin_port
"
)
self
.
memcached_port
=
self
.
get_option
_int
(
config
,
dummy_section_name
,
"
memcached_port
"
)
self
.
memcached_port
=
get_option
(
config
,
dummy_section_name
,
"
memcached_port
"
)
self
.
port
=
self
.
admin_port
self
.
port
=
self
.
admin_port
self
.
admin
=
AdminConnection
(
"
localhost
"
,
self
.
admin_port
)
self
.
admin
=
AdminConnection
(
"
localhost
"
,
self
.
admin_port
)
...
@@ -240,9 +207,13 @@ class TarantoolServer(Server):
...
@@ -240,9 +207,13 @@ class TarantoolServer(Server):
stderr
=
subprocess
.
PIPE
)
stderr
=
subprocess
.
PIPE
)
def
get_param
(
self
,
param
):
def
get_param
(
self
,
param
):
data
=
self
.
admin
.
execute
(
"
show info
"
,
silent
=
True
)
if
param
!=
None
:
info
=
yaml
.
load
(
data
)[
"
info
"
]
data
=
self
.
admin
(
"
show.info.
"
+
param
)
return
info
[
param
]
info
=
yaml
.
load
(
data
)
else
:
data
=
self
.
admin
.
execute
(
"
show info
"
,
silent
=
True
)
info
=
yaml
.
load
(
data
)[
"
info
"
]
return
info
def
wait_lsn
(
self
,
lsn
):
def
wait_lsn
(
self
,
lsn
):
while
True
:
while
True
:
...
@@ -265,7 +236,7 @@ class TarantoolServer(Server):
...
@@ -265,7 +236,7 @@ class TarantoolServer(Server):
if
self
.
valgrind
:
if
self
.
valgrind
:
with
daemon
.
DaemonContext
(
working_directory
=
self
.
vardir
):
with
daemon
.
DaemonContext
(
working_directory
=
self
.
vardir
):
subprocess
.
check_call
(
args
)
subprocess
.
check_call
(
arg
s
)
else
:
else
:
if
not
self
.
gdb
:
if
not
self
.
gdb
:
args
.
append
(
"
--background
"
)
args
.
append
(
"
--background
"
)
...
...
This diff is collapsed.
Click to expand it.
test/lib/test_suite.py
+
21
−
5
View file @
e049d314
...
@@ -96,7 +96,6 @@ class Test:
...
@@ -96,7 +96,6 @@ class Test:
def
passed
(
self
):
def
passed
(
self
):
"""
Return true if this test was run successfully.
"""
"""
Return true if this test was run successfully.
"""
return
self
.
is_executed
and
self
.
is_executed_ok
and
self
.
is_equal_result
return
self
.
is_executed
and
self
.
is_executed_ok
and
self
.
is_equal_result
def
run
(
self
,
server
):
def
run
(
self
,
server
):
...
@@ -106,11 +105,28 @@ class Test:
...
@@ -106,11 +105,28 @@ class Test:
If there is a difference, print it to stdout and raise an
If there is a difference, print it to stdout and raise an
exception. The exception is raised only if is_force flag is
exception. The exception is raised only if is_force flag is
not set.
"""
not set.
"""
diagnostics
=
"
unknown
"
diagnostics
=
"
unknown
"
builddir
=
self
.
args
.
builddir
save_stdout
=
sys
.
stdout
self
.
execute
(
server
)
try
:
self
.
skip
=
0
if
os
.
path
.
exists
(
self
.
skip_cond
):
sys
.
stdout
=
FilteredStream
(
self
.
tmp_result
)
stdout_fileno
=
sys
.
stdout
.
stream
.
fileno
()
execfile
(
self
.
skip_cond
,
dict
(
locals
(),
**
server
.
__dict__
))
sys
.
stdout
.
close
()
sys
.
stdout
=
save_stdout
if
not
self
.
skip
:
sys
.
stdout
=
FilteredStream
(
self
.
tmp_result
)
stdout_fileno
=
sys
.
stdout
.
stream
.
fileno
()
self
.
execute
(
server
)
self
.
is_executed_ok
=
True
except
Exception
as
e
:
traceback
.
print_exc
(
e
)
diagnostics
=
str
(
e
)
finally
:
if
sys
.
stdout
and
sys
.
stdout
!=
save_stdout
:
sys
.
stdout
.
close
()
sys
.
stdout
=
save_stdout
;
self
.
is_executed
=
True
self
.
is_executed
=
True
if
not
self
.
skip
:
if
not
self
.
skip
:
...
...
This diff is collapsed.
Click to expand it.
test/lib/unittest_server.py
+
9
−
69
View file @
e049d314
import
os
import
os
import
re
import
re
import
sys
import
sys
import
glob
import
traceback
import
traceback
import
subprocess
import
subprocess
from
subprocess
import
Popen
,
PIPE
from
subprocess
import
Popen
,
PIPE
from
server
import
Server
from
server
import
Server
from
test_suite
import
FilteredStream
,
Test
from
test_suite
import
FilteredStream
,
Test
class
UnitTest
(
Test
):
class
UnitTest
(
Test
):
def
__init__
(
self
,
name
,
args
,
suite_ini
):
Test
.
__init__
(
self
,
name
,
args
,
suite_ini
)
self
.
name
=
name
+
"
.test
"
self
.
result
=
name
+
"
.result
"
self
.
skip_cond
=
name
+
"
.skipcond
"
self
.
tmp_result
=
os
.
path
.
join
(
self
.
args
.
vardir
,
os
.
path
.
basename
(
self
.
result
))
self
.
reject
=
"
{0}/test/{1}
"
.
format
(
self
.
args
.
builddir
,
name
+
"
.reject
"
)
def
execute
(
self
,
server
):
def
execute
(
self
,
server
):
diagnostics
=
"
unknown
"
execs
=
[
os
.
path
.
join
(
server
.
builddir
,
"
test
"
,
self
.
name
)]
builddir
=
self
.
args
.
builddir
proc
=
Popen
(
execs
,
stdout
=
PIPE
)
save_stdout
=
sys
.
stdout
sys
.
stdout
.
write
(
proc
.
communicate
()[
0
])
try
:
self
.
skip
=
0
if
os
.
path
.
exists
(
self
.
skip_cond
):
sys
.
stdout
=
FilteredStream
(
self
.
tmp_result
)
stdout_fileno
=
sys
.
stdout
.
stream
.
fileno
()
execfile
(
self
.
skip_cond
,
dict
(
locals
(),
**
server
.
__dict__
))
sys
.
stdout
.
close
()
sys
.
stdout
=
save_stdout
if
not
self
.
skip
:
sys
.
stdout
=
FilteredStream
(
self
.
tmp_result
)
stdout_fileno
=
sys
.
stdout
.
stream
.
fileno
()
execs
=
[
os
.
path
.
join
(
server
.
builddir
,
"
test
"
,
self
.
name
)]
proc
=
Popen
(
execs
,
stdout
=
PIPE
)
sys
.
stdout
.
write
(
proc
.
communicate
()[
0
])
self
.
is_executed_ok
=
True
except
Exception
as
e
:
traceback
.
print_exc
(
e
)
diagnostics
=
str
(
e
)
finally
:
if
sys
.
stdout
and
sys
.
stdout
!=
save_stdout
:
sys
.
stdout
.
close
()
sys
.
stdout
=
save_stdout
;
self
.
is_executed
=
True
def
__repr__
(
self
):
return
str
([
self
.
name
,
self
.
result
,
self
.
skip_cond
,
self
.
tmp_result
,
self
.
reject
])
__str__
=
__repr__
class
UnittestServer
(
Server
):
class
UnittestServer
(
Server
):
"""
A dummy server implementation for unit test suite
"""
"""
A dummy server implementation for unit test suite
"""
def
__new__
(
cls
,
core
=
"
unittest
"
):
def
__new__
(
cls
,
core
=
"
unittest
"
):
return
Server
.
__new__
(
cls
)
return
Server
.
__new__
(
cls
)
def
__init__
(
self
,
core
=
"
unittest
"
):
def
__init__
(
self
,
core
=
"
unittest
"
):
Server
.
__init__
(
self
,
core
)
Server
.
__init__
(
self
,
core
)
self
.
debug
=
False
self
.
debug
=
False
def
configure
(
self
,
config
):
pass
def
deploy
(
self
,
config
=
None
,
binary
=
None
,
vardir
=
None
,
def
deploy
(
self
,
config
=
None
,
binary
=
None
,
vardir
=
None
,
mem
=
None
,
start_and_exit
=
None
,
gdb
=
None
,
valgrind
=
None
,
mem
=
None
,
start_and_exit
=
None
,
gdb
=
None
,
valgrind
=
None
,
valgrind_sup
=
None
,
init_lua
=
None
,
silent
=
True
,
need_init
=
True
):
valgrind_sup
=
None
,
init_lua
=
None
,
silent
=
True
,
need_init
=
True
):
self
.
vardir
=
vardir
self
.
vardir
=
vardir
if
not
os
.
access
(
self
.
vardir
,
os
.
F_OK
):
if
not
os
.
access
(
self
.
vardir
,
os
.
F_OK
):
if
(
self
.
mem
==
True
and
check_tmpfs_exists
()
and
os
.
makedirs
(
self
.
vardir
)
os
.
path
.
basename
(
self
.
vardir
)
==
self
.
vardir
):
create_tmpfs_vardir
(
self
.
vardir
)
else
:
os
.
makedirs
(
self
.
vardir
)
def
start
(
self
):
pass
def
find_exe
(
self
,
builddir
,
silent
=
False
):
def
find_exe
(
self
,
builddir
,
silent
=
False
):
self
.
builddir
=
builddir
self
.
builddir
=
builddir
...
@@ -92,15 +40,7 @@ class UnittestServer(Server):
...
@@ -92,15 +40,7 @@ class UnittestServer(Server):
if
name
.
find
(
i
)
!=
-
1
:
if
name
.
find
(
i
)
!=
-
1
:
return
True
return
True
return
False
return
False
for
f
in
sorted
(
glob
.
glob
(
os
.
path
.
join
(
suite_path
,
'
*.test
'
))):
regexp
=
re
.
compile
(
'
([a-zA-Z0-9_]*).test
'
)
if
os
.
access
(
f
,
os
.
X_OK
)
and
os
.
path
.
isfile
(
f
)
and
patterned
(
f
):
for
f
in
sorted
(
os
.
listdir
(
suite_path
)):
test_suite
.
tests
.
append
(
UnitTest
(
f
,
test_suite
.
args
,
if
regexp
.
match
(
f
):
test_suite
.
ini
));
f
=
os
.
path
.
join
(
suite_path
,
regexp
.
match
(
f
).
groups
()[
0
])
+
'
.test
'
if
os
.
access
(
f
,
os
.
X_OK
)
and
os
.
path
.
isfile
(
f
)
and
patterned
(
f
):
test_suite
.
tests
.
append
(
UnitTest
(
f
[:
-
5
],
test_suite
.
args
,
test_suite
.
ini
));
def
init
(
self
):
pass
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