|
2 | 2 | import os
|
3 | 3 | import re
|
4 | 4 | import subprocess
|
5 |
| -import tempfile |
6 | 5 | import time
|
7 | 6 | import pytest
|
8 | 7 | import psutil
|
9 | 8 | import platform
|
10 | 9 | import logging
|
11 |
| -import uuid |
12 | 10 |
|
13 | 11 | from contextlib import contextmanager
|
14 | 12 | from shutil import rmtree
|
|
21 | 19 | ExecUtilException, \
|
22 | 20 | BackupException, \
|
23 | 21 | QueryException, \
|
24 |
| - TimeoutException, \ |
25 | 22 | TestgresException, \
|
26 | 23 | InvalidOperationException, \
|
27 | 24 | NodeApp
|
@@ -703,165 +700,6 @@ def test_dump(self):
|
703 | 700 | res = node3.execute(query_select)
|
704 | 701 | assert (res == [(1, ), (2, )])
|
705 | 702 |
|
706 |
| - def test_users(self): |
707 |
| - with get_new_node().init().start() as node: |
708 |
| - node.psql('create role test_user login') |
709 |
| - value = node.safe_psql('select 1', username='test_user') |
710 |
| - value = rm_carriage_returns(value) |
711 |
| - assert (value == b'1\n') |
712 |
| - |
713 |
| - def test_poll_query_until(self): |
714 |
| - with get_new_node() as node: |
715 |
| - node.init().start() |
716 |
| - |
717 |
| - get_time = 'select extract(epoch from now())' |
718 |
| - check_time = 'select extract(epoch from now()) - {} >= 5' |
719 |
| - |
720 |
| - start_time = node.execute(get_time)[0][0] |
721 |
| - node.poll_query_until(query=check_time.format(start_time)) |
722 |
| - end_time = node.execute(get_time)[0][0] |
723 |
| - |
724 |
| - assert (end_time - start_time >= 5) |
725 |
| - |
726 |
| - # check 0 columns |
727 |
| - with pytest.raises(expected_exception=QueryException): |
728 |
| - node.poll_query_until( |
729 |
| - query='select from pg_catalog.pg_class limit 1') |
730 |
| - |
731 |
| - # check None, fail |
732 |
| - with pytest.raises(expected_exception=QueryException): |
733 |
| - node.poll_query_until(query='create table abc (val int)') |
734 |
| - |
735 |
| - # check None, ok |
736 |
| - node.poll_query_until(query='create table def()', |
737 |
| - expected=None) # returns nothing |
738 |
| - |
739 |
| - # check 0 rows equivalent to expected=None |
740 |
| - node.poll_query_until( |
741 |
| - query='select * from pg_catalog.pg_class where true = false', |
742 |
| - expected=None) |
743 |
| - |
744 |
| - # check arbitrary expected value, fail |
745 |
| - with pytest.raises(expected_exception=TimeoutException): |
746 |
| - node.poll_query_until(query='select 3', |
747 |
| - expected=1, |
748 |
| - max_attempts=3, |
749 |
| - sleep_time=0.01) |
750 |
| - |
751 |
| - # check arbitrary expected value, ok |
752 |
| - node.poll_query_until(query='select 2', expected=2) |
753 |
| - |
754 |
| - # check timeout |
755 |
| - with pytest.raises(expected_exception=TimeoutException): |
756 |
| - node.poll_query_until(query='select 1 > 2', |
757 |
| - max_attempts=3, |
758 |
| - sleep_time=0.01) |
759 |
| - |
760 |
| - # check ProgrammingError, fail |
761 |
| - with pytest.raises(expected_exception=testgres.ProgrammingError): |
762 |
| - node.poll_query_until(query='dummy1') |
763 |
| - |
764 |
| - # check ProgrammingError, ok |
765 |
| - with pytest.raises(expected_exception=(TimeoutException)): |
766 |
| - node.poll_query_until(query='dummy2', |
767 |
| - max_attempts=3, |
768 |
| - sleep_time=0.01, |
769 |
| - suppress={testgres.ProgrammingError}) |
770 |
| - |
771 |
| - # check 1 arg, ok |
772 |
| - node.poll_query_until('select true') |
773 |
| - |
774 |
| - def test_logging(self): |
775 |
| - C_MAX_ATTEMPTS = 50 |
776 |
| - # This name is used for testgres logging, too. |
777 |
| - C_NODE_NAME = "testgres_tests." + __class__.__name__ + "test_logging-master-" + uuid.uuid4().hex |
778 |
| - |
779 |
| - logging.info("Node name is [{0}]".format(C_NODE_NAME)) |
780 |
| - |
781 |
| - with tempfile.NamedTemporaryFile('w', delete=True) as logfile: |
782 |
| - formatter = logging.Formatter(fmt="%(node)-5s: %(message)s") |
783 |
| - handler = logging.FileHandler(filename=logfile.name) |
784 |
| - handler.formatter = formatter |
785 |
| - logger = logging.getLogger(C_NODE_NAME) |
786 |
| - assert logger is not None |
787 |
| - assert len(logger.handlers) == 0 |
788 |
| - |
789 |
| - try: |
790 |
| - # It disables to log on the root level |
791 |
| - logger.propagate = False |
792 |
| - logger.addHandler(handler) |
793 |
| - |
794 |
| - with scoped_config(use_python_logging=True): |
795 |
| - with get_new_node(name=C_NODE_NAME) as master: |
796 |
| - logging.info("Master node is initilizing") |
797 |
| - master.init() |
798 |
| - |
799 |
| - logging.info("Master node is starting") |
800 |
| - master.start() |
801 |
| - |
802 |
| - logging.info("Dummy query is executed a few times") |
803 |
| - for _ in range(20): |
804 |
| - master.execute('select 1') |
805 |
| - time.sleep(0.01) |
806 |
| - |
807 |
| - # let logging worker do the job |
808 |
| - time.sleep(0.1) |
809 |
| - |
810 |
| - logging.info("Master node log file is checking") |
811 |
| - nAttempt = 0 |
812 |
| - |
813 |
| - while True: |
814 |
| - assert nAttempt <= C_MAX_ATTEMPTS |
815 |
| - if nAttempt == C_MAX_ATTEMPTS: |
816 |
| - raise Exception("Test failed!") |
817 |
| - |
818 |
| - # let logging worker do the job |
819 |
| - time.sleep(0.1) |
820 |
| - |
821 |
| - nAttempt += 1 |
822 |
| - |
823 |
| - logging.info("Attempt {0}".format(nAttempt)) |
824 |
| - |
825 |
| - # check that master's port is found |
826 |
| - with open(logfile.name, 'r') as log: |
827 |
| - lines = log.readlines() |
828 |
| - |
829 |
| - assert lines is not None |
830 |
| - assert type(lines) == list # noqa: E721 |
831 |
| - |
832 |
| - def LOCAL__test_lines(): |
833 |
| - for s in lines: |
834 |
| - if any(C_NODE_NAME in s for s in lines): |
835 |
| - logging.info("OK. We found the node_name in a line \"{0}\"".format(s)) |
836 |
| - return True |
837 |
| - return False |
838 |
| - |
839 |
| - if LOCAL__test_lines(): |
840 |
| - break |
841 |
| - |
842 |
| - logging.info("Master node log file does not have an expected information.") |
843 |
| - continue |
844 |
| - |
845 |
| - # test logger after stop/start/restart |
846 |
| - logging.info("Master node is stopping...") |
847 |
| - master.stop() |
848 |
| - logging.info("Master node is staring again...") |
849 |
| - master.start() |
850 |
| - logging.info("Master node is restaring...") |
851 |
| - master.restart() |
852 |
| - assert (master._logger.is_alive()) |
853 |
| - finally: |
854 |
| - # It is a hack code to logging cleanup |
855 |
| - logging._acquireLock() |
856 |
| - assert logging.Logger.manager is not None |
857 |
| - assert C_NODE_NAME in logging.Logger.manager.loggerDict.keys() |
858 |
| - logging.Logger.manager.loggerDict.pop(C_NODE_NAME, None) |
859 |
| - assert not (C_NODE_NAME in logging.Logger.manager.loggerDict.keys()) |
860 |
| - assert not (handler in logging._handlers.values()) |
861 |
| - logging._releaseLock() |
862 |
| - # GO HOME! |
863 |
| - return |
864 |
| - |
865 | 703 | def test_pgbench(self):
|
866 | 704 | __class__.helper__skip_test_if_util_not_exist("pgbench")
|
867 | 705 |
|
|
0 commit comments