tests/delayedquery.py
author Radek Brich <radek.brich@devl.cz>
Tue, 06 Dec 2011 16:45:29 +0100
changeset 21 26209e9984b2
child 22 680631f35d83
permissions -rwxr-xr-x
Add test for delayedquery.
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
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
from pgtoolkit import pgmanager
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
from pgtoolkit.delayedquery import DelayedQuery
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
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
class Config(dict):
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    def __init__(self, fname):
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        data = open(fname).read()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        exec(data, dict(), self)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
if __name__ == '__main__':
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
    cfg = Config('tests.conf')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
    pgm = pgmanager.get_instance()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
    pgm.create_conn(isolation_level = 'autocommit', **cfg)
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
    handler = logging.StreamHandler()
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
    logger = logging.getLogger('pgmanager')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
    logger.addHandler(handler)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
    logger.setLevel(logging.DEBUG)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
    dq = DelayedQuery(pgm)
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
    print('add 1')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
    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
    31
    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
    32
    print('after 1')
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
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
    print('add 2')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
    dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
    
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
    time.sleep(5)
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
    print('after 10')
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
26209e9984b2 Add test for delayedquery.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
    time.sleep(10)