tests/delayedquery.py
author Radek Brich <radek.brich@devl.cz>
Wed, 23 May 2012 11:11:16 +0200
changeset 36 e67101c22e83
parent 22 680631f35d83
child 78 64c62ac8f65d
permissions -rwxr-xr-x
pgmanager: Add create_conn_listen() which should be used with wait_for_notify. Update wait_for_notify() to not use put_conn(). Add name to ConnectionInfo. Log queries before they are called. Log exceptions. Add notifyexample.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
import logging
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import time
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
22
680631f35d83 Add test for PgManager.
Radek Brich <radek.brich@devl.cz>
parents: 21
diff changeset
     6
from config import Config
21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
from pgtoolkit import pgmanager
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
from pgtoolkit.delayedquery import DelayedQuery
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
if __name__ == '__main__':
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
    cfg = Config('tests.conf')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
    pgm = pgmanager.get_instance()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    pgm.create_conn(isolation_level = 'autocommit', **cfg)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
    handler = logging.StreamHandler()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
    logger = logging.getLogger('pgmanager')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
    logger.addHandler(handler)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
    logger.setLevel(logging.DEBUG)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
    dq = DelayedQuery(pgm)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
    print('add 1')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
    print('after 1')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
    time.sleep(5)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
    print('add 2')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
    time.sleep(5)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
    print('after 10')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
    time.sleep(10)