Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
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
mediaserver
envsetup
Commits
1b65a39d
Commit
1b65a39d
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
change(test_postgresql): separte write/read/del statements, and use a incremental timer for read
parent
1b717cc3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_postgresql.py
+30
-6
30 additions, 6 deletions
tests/test_postgresql.py
with
30 additions
and
6 deletions
tests/test_postgresql.py
+
30
−
6
View file @
1b65a39d
...
@@ -11,6 +11,7 @@ import socket
...
@@ -11,6 +11,7 @@ import socket
import
subprocess
import
subprocess
import
sys
import
sys
import
time
import
time
import
uuid
try
:
try
:
import
psycopg2
import
psycopg2
...
@@ -250,17 +251,40 @@ def check_replication(primary: dict, standby: dict) -> bool:
...
@@ -250,17 +251,40 @@ def check_replication(primary: dict, standby: dict) -> bool:
error
(
"
Cannot connect to the databases
"
)
error
(
"
Cannot connect to the databases
"
)
return
False
return
False
# queries
# random id
rand
=
uuid
.
uuid4
().
hex
write_query
=
"
CREATE TABLE es_test_{} (id serial PRIMARY KEY);
"
.
format
(
rand
)
read_query
=
"
SELECT * FROM es_test_{};
"
.
format
(
rand
)
del_query
=
"
DROP TABLE es_test_{};
"
.
format
(
rand
)
# write
try
:
try
:
primary_psql
=
primary_client
.
cursor
()
primary_psql
=
primary_client
.
cursor
()
primary_psql
.
execute
(
"
CREATE TABLE es_test (id serial PRIMARY KEY);
"
)
primary_psql
.
execute
(
write_query
)
time
.
sleep
(
3
)
standby_psql
=
primary_client
.
cursor
()
standby_psql
.
execute
(
"
SELECT * FROM es_test;
"
)
primary_psql
.
execute
(
"
DROP TABLE es_test;
"
)
except
psycopg2
.
Error
:
except
psycopg2
.
Error
:
return
False
return
False
# read
max_time
=
6.0
timer
=
0.0
while
timer
<
max_time
:
time
.
sleep
(
timer
)
timer
+=
0.2
try
:
standby_psql
=
primary_client
.
cursor
()
standby_psql
.
execute
(
read_query
)
break
except
psycopg2
.
Error
:
pass
else
:
return
False
# delete
try
:
primary_psql
.
execute
(
del_query
)
except
psycopg2
.
Error
:
pass
# close
# close
primary_psql
.
close
()
primary_psql
.
close
()
standby_psql
.
close
()
standby_psql
.
close
()
...
...
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