Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: third_party/buildbot_8_4p1/buildbot/test/unit/test_db_pool.py

Issue 2103053002: Cherry-pick buildbot 95deef27d7c531ead19e0ac86a9aa1546d4ee7f9: (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@buildbot-version-2
Patch Set: Disable the test again Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # This file is part of Buildbot. Buildbot is free software: you can 1 # This file is part of Buildbot. Buildbot is free software: you can
2 # redistribute it and/or modify it under the terms of the GNU General Public 2 # redistribute it and/or modify it under the terms of the GNU General Public
3 # License as published by the Free Software Foundation, version 2. 3 # License as published by the Free Software Foundation, version 2.
4 # 4 #
5 # This program is distributed in the hope that it will be useful, but WITHOUT 5 # This program is distributed in the hope that it will be useful, but WITHOUT
6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
8 # details. 8 # details.
9 # 9 #
10 # You should have received a copy of the GNU General Public License along with 10 # You should have received a copy of the GNU General Public License along with
11 # this program; if not, write to the Free Software Foundation, Inc., 51 11 # this program; if not, write to the Free Software Foundation, Inc., 51
12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
13 # 13 #
14 # Copyright Buildbot Team Members 14 # Copyright Buildbot Team Members
15 15
16 import os
17 import time
16 import sqlalchemy as sa 18 import sqlalchemy as sa
17 from twisted.trial import unittest 19 from twisted.trial import unittest
18 from twisted.internet import defer 20 from twisted.internet import defer, reactor
19 from buildbot.db import pool 21 from buildbot.db import pool
20 from buildbot.test.util import db 22 from buildbot.test.util import db
21 23
22 class Basic(unittest.TestCase): 24 class Basic(unittest.TestCase):
23 25
24 # basic tests, just using an in-memory SQL db and one thread 26 # basic tests, just using an in-memory SQL db and one thread
25 27
26 def setUp(self): 28 def setUp(self):
27 self.engine = sa.create_engine('sqlite://') 29 self.engine = sa.create_engine('sqlite://')
28 self.engine.optimal_thread_pool_size = 1 30 self.engine.optimal_thread_pool_size = 1
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 # setUp. 98 # setUp.
97 d = defer.succeed(None) 99 d = defer.succeed(None)
98 def create_table(engine): 100 def create_table(engine):
99 engine.execute("CREATE TABLE tmp ( a integer )") 101 engine.execute("CREATE TABLE tmp ( a integer )")
100 d.addCallback( lambda r : self.pool.do_with_engine(create_table)) 102 d.addCallback( lambda r : self.pool.do_with_engine(create_table))
101 def insert_into_table(engine): 103 def insert_into_table(engine):
102 engine.execute("INSERT INTO tmp values ( 1 )") 104 engine.execute("INSERT INTO tmp values ( 1 )")
103 d.addCallback( lambda r : self.pool.do_with_engine(insert_into_table)) 105 d.addCallback( lambda r : self.pool.do_with_engine(insert_into_table))
104 return d 106 return d
105 107
108
109 class Stress(unittest.TestCase):
110
111 def setUp(self):
112 setup_engine = sa.create_engine('sqlite:///test.sqlite')
113 setup_engine.execute("pragma journal_mode = wal")
114 setup_engine.execute("CREATE TABLE test (a integer, b integer)")
115
116 self.engine = sa.create_engine('sqlite:///test.sqlite')
117 self.engine.optimal_thread_pool_size = 2
118 self.pool = pool.DBThreadPool(self.engine)
119
120 def tearDown(self):
121 self.pool.shutdown()
122 os.unlink("test.sqlite")
123
124 @defer.deferredGenerator
125 def test_inserts(self):
126 def write(conn):
127 trans = conn.begin()
128 conn.execute("INSERT INTO test VALUES (1, 1)")
129 time.sleep(31)
130 trans.commit()
131 d1 = self.pool.do(write)
132
133 def write2(conn):
134 trans = conn.begin()
135 conn.execute("INSERT INTO test VALUES (1, 1)")
136 trans.commit()
137 d2 = defer.Deferred()
138 d2.addCallback(lambda _ :
139 self.pool.do(write2))
140 reactor.callLater(0.1, d2.callback, None)
141
142 wfd = defer.waitForDeferred(
143 defer.DeferredList([ d1, d2 ]))
144 yield wfd
145 wfd.getResult()
146
147 # don't run this test, since it takes 30s
148 del test_inserts
149
150
106 class Native(unittest.TestCase, db.RealDatabaseMixin): 151 class Native(unittest.TestCase, db.RealDatabaseMixin):
107 152
108 # similar tests, but using the BUILDBOT_TEST_DB_URL 153 # similar tests, but using the BUILDBOT_TEST_DB_URL
109 154
110 def setUp(self): 155 def setUp(self):
111 d = self.setUpRealDatabase(want_pool=False) 156 d = self.setUpRealDatabase(want_pool=False)
112 def make_pool(_): 157 def make_pool(_):
113 self.pool = pool.DBThreadPool(self.db_engine) 158 self.pool = pool.DBThreadPool(self.db_engine)
114 d.addCallback(make_pool) 159 d.addCallback(make_pool)
115 return d 160 return d
(...skipping 21 matching lines...) Expand all
137 t = conn.begin() 182 t = conn.begin()
138 native_tests.create(bind=conn) 183 native_tests.create(bind=conn)
139 t.commit() 184 t.commit()
140 d = self.pool.do(ddl) 185 d = self.pool.do(ddl)
141 def access(conn): 186 def access(conn):
142 native_tests.insert(bind=conn).execute([ {'name':'foo'} ]) 187 native_tests.insert(bind=conn).execute([ {'name':'foo'} ])
143 d.addCallback(lambda _ : 188 d.addCallback(lambda _ :
144 self.pool.do(access)) 189 self.pool.do(access))
145 return d 190 return d
146 191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698