# HG changeset patch # User Radek Brich # Date 1323186329 -3600 # Node ID 26209e9984b2671ea9250d292cd209faa7f7d904 # Parent 73f0d53fef6b12b7df34161b31be6af9519e2cc2 Add test for delayedquery. diff -r 73f0d53fef6b -r 26209e9984b2 .hgignore --- a/.hgignore Tue Dec 06 16:20:53 2011 +0100 +++ b/.hgignore Tue Dec 06 16:45:29 2011 +0100 @@ -1,3 +1,7 @@ .*\.pyc +.project +.pydevproject +.settings/org.eclipse.core.resources.prefs pgtoolkit\.conf build +tests/tests\.conf diff -r 73f0d53fef6b -r 26209e9984b2 extras/test-db.sql --- a/extras/test-db.sql Tue Dec 06 16:20:53 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -CREATE TABLE test -( - id serial NOT NULL, - name varchar, - PRIMARY KEY (id) -); diff -r 73f0d53fef6b -r 26209e9984b2 tests/delayedquery.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/delayedquery.py Tue Dec 06 16:45:29 2011 +0100 @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import logging +import time + +from pgtoolkit import pgmanager +from pgtoolkit.delayedquery import DelayedQuery + + +class Config(dict): + def __init__(self, fname): + data = open(fname).read() + exec(data, dict(), self) + + +if __name__ == '__main__': + cfg = Config('tests.conf') + + pgm = pgmanager.get_instance() + pgm.create_conn(isolation_level = 'autocommit', **cfg) + + handler = logging.StreamHandler() + logger = logging.getLogger('pgmanager') + logger.addHandler(handler) + logger.setLevel(logging.DEBUG) + + dq = DelayedQuery(pgm) + + print('add 1') + dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1) + dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1) + print('after 1') + + time.sleep(5) + + print('add 2') + dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2']) + + time.sleep(5) + print('after 10') + + time.sleep(10) diff -r 73f0d53fef6b -r 26209e9984b2 tests/tests.conf.example --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/tests.conf.example Tue Dec 06 16:45:29 2011 +0100 @@ -0,0 +1,4 @@ +hostaddr='127.0.0.1' +dbname='test' +user='test' +password='pass' diff -r 73f0d53fef6b -r 26209e9984b2 tests/tests.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/tests.sql Tue Dec 06 16:45:29 2011 +0100 @@ -0,0 +1,6 @@ +CREATE TABLE test +( + id serial NOT NULL, + name varchar, + PRIMARY KEY (id) +);