Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor 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
RadioObservatory
LOFAR
Commits
1fab7b8c
Commit
1fab7b8c
authored
5 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
SW-816
: major speedup of test database setup and preparations for each test
parent
4525fc32
No related branches found
No related tags found
2 merge requests
!59
Merge LOFAR-Release-4_0 into master
,
!57
Resolve SW-816
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/ResourceAssignment/ResourceAssignmentDatabase/tests/radb_common_testing.py
+32
-29
32 additions, 29 deletions
...t/ResourceAssignmentDatabase/tests/radb_common_testing.py
with
32 additions
and
29 deletions
SAS/ResourceAssignment/ResourceAssignmentDatabase/tests/radb_common_testing.py
+
32
−
29
View file @
1fab7b8c
...
...
@@ -39,7 +39,7 @@ class RADBCommonTestMixin():
@classmethod
def
setUpClass
(
cls
):
logger
.
info
(
'
setting up test
RA
database...
'
)
logger
.
info
(
'
setting up test database
instance
...
'
)
# connect to shared test db
cls
.
postgresql
=
testing
.
postgresql
.
PostgresqlFactory
(
cache_initialized_db
=
True
)()
cls
.
dbcreds
=
Credentials
()
...
...
@@ -67,21 +67,24 @@ class RADBCommonTestMixin():
conn
.
commit
()
conn
.
close
()
logger
.
info
(
'
Finished setting up test
RA
database. It is avaiblable at: %s
'
,
cls
.
dbcreds
.
stringWithHiddenPassword
())
logger
.
info
(
'
Finished setting up test database
instance
. It is avaiblable at: %s
'
,
cls
.
dbcreds
.
stringWithHiddenPassword
())
def
setUp
(
self
):
# set up a fresh copy of the RADB sql schema
self
.
_setup_database
()
cls
.
radb
=
RADatabase
(
cls
.
dbcreds
)
cls
.
radb
.
connect
()
# set up radb python module
self
.
radb
=
RADatabase
(
self
.
dbcreds
)
self
.
radb
.
connect
()
# set up a fresh copy of the RADB sql schema
cls
.
_setup_database
(
cls
.
radb
)
def
tearDown
(
self
):
self
.
radb
.
disconnect
()
def
setUp
(
self
):
# wipe all tables by truncating specification which cascades into the rest.
logger
.
debug
(
"
setUp: Wiping radb tables for each unittest.
"
)
self
.
radb
.
executeQuery
(
"
TRUNCATE TABLE resource_allocation.specification CASCADE;
"
)
self
.
radb
.
commit
()
@classmethod
def
tearDownClass
(
cls
):
cls
.
radb
.
disconnect
()
db_log_file_name
=
os
.
path
.
join
(
cls
.
postgresql
.
base_dir
,
'
%s.log
'
%
cls
.
postgresql
.
name
)
logger
.
info
(
'
Printing test-postgress-database server log: %s
'
,
db_log_file_name
)
with
open
(
db_log_file_name
,
'
r
'
)
as
db_log_file
:
...
...
@@ -92,25 +95,25 @@ class RADBCommonTestMixin():
cls
.
postgresql
.
stop
()
logger
.
info
(
'
test RA removed
'
)
def
_setup_database
(
self
):
logger
.
info
(
'
applying RADB sql schema to %s
'
,
self
.
dbcreds
.
stringWithHiddenPassword
())
with
PostgresDatabaseConnection
(
self
.
dbcreds
)
as
db
:
# populate db tables
# These are applied in given order to set up test db
# Note: cannot use create_and_populate_database.sql since '\i' is not understood by cursor.execute()
sql_basepath
=
os
.
environ
[
'
LOFARROOT
'
]
+
"
/share/radb/sql/
"
sql_createdb_paths
=
[
sql_basepath
+
"
create_database.sql
"
,
sql_basepath
+
"
/add_resource_allocation_statics.sql
"
,
sql_basepath
+
"
/add_virtual_instrument.sql
"
,
sql_basepath
+
"
/add_notifications.sql
"
,
sql_basepath
+
"
/add_functions_and_triggers.sql
"
]
for
sql_path
in
sql_createdb_paths
:
logger
.
debug
(
"
setting up database. applying sql file: %s
"
,
sql_path
)
with
open
(
sql_path
)
as
sql
:
db
.
executeQuery
(
sql
.
read
())
@staticmethod
def
_setup_database
(
db
:
PostgresDatabaseConnection
):
logger
.
info
(
'
applying RADB sql schema to %s
'
,
db
)
# populate db tables
# These are applied in given order to set up test db
# Note: cannot use create_and_populate_database.sql since '\i' is not understood by cursor.execute()
sql_basepath
=
os
.
environ
[
'
LOFARROOT
'
]
+
"
/share/radb/sql/
"
sql_createdb_paths
=
[
sql_basepath
+
"
create_database.sql
"
,
sql_basepath
+
"
/add_resource_allocation_statics.sql
"
,
sql_basepath
+
"
/add_virtual_instrument.sql
"
,
sql_basepath
+
"
/add_notifications.sql
"
,
sql_basepath
+
"
/add_functions_and_triggers.sql
"
]
for
sql_path
in
sql_createdb_paths
:
logger
.
debug
(
"
setting up database. applying sql file: %s
"
,
sql_path
)
with
open
(
sql_path
)
as
sql
:
db
.
executeQuery
(
sql
.
read
())
db
.
commit
()
class
RADBCommonTest
(
RADBCommonTestMixin
,
unittest
.
TestCase
):
# database created?
...
...
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