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

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

Issue 2128953002: Revert of Cherry-pick buildbot 95deef27d7c531ead19e0ac86a9aa1546d4ee7f9: (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@buildbot-version-2
Patch Set: 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
« no previous file with comments | « third_party/buildbot_8_4p1/buildbot/db/pool.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
18 import sqlalchemy as sa 16 import sqlalchemy as sa
19 from twisted.trial import unittest 17 from twisted.trial import unittest
20 from twisted.internet import defer, reactor 18 from twisted.internet import defer
21 from buildbot.db import pool 19 from buildbot.db import pool
22 from buildbot.test.util import db 20 from buildbot.test.util import db
23 21
24 class Basic(unittest.TestCase): 22 class Basic(unittest.TestCase):
25 23
26 # basic tests, just using an in-memory SQL db and one thread 24 # basic tests, just using an in-memory SQL db and one thread
27 25
28 def setUp(self): 26 def setUp(self):
29 self.engine = sa.create_engine('sqlite://') 27 self.engine = sa.create_engine('sqlite://')
30 self.engine.optimal_thread_pool_size = 1 28 self.engine.optimal_thread_pool_size = 1
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 # setUp. 96 # setUp.
99 d = defer.succeed(None) 97 d = defer.succeed(None)
100 def create_table(engine): 98 def create_table(engine):
101 engine.execute("CREATE TABLE tmp ( a integer )") 99 engine.execute("CREATE TABLE tmp ( a integer )")
102 d.addCallback( lambda r : self.pool.do_with_engine(create_table)) 100 d.addCallback( lambda r : self.pool.do_with_engine(create_table))
103 def insert_into_table(engine): 101 def insert_into_table(engine):
104 engine.execute("INSERT INTO tmp values ( 1 )") 102 engine.execute("INSERT INTO tmp values ( 1 )")
105 d.addCallback( lambda r : self.pool.do_with_engine(insert_into_table)) 103 d.addCallback( lambda r : self.pool.do_with_engine(insert_into_table))
106 return d 104 return d
107 105
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
151 class Native(unittest.TestCase, db.RealDatabaseMixin): 106 class Native(unittest.TestCase, db.RealDatabaseMixin):
152 107
153 # similar tests, but using the BUILDBOT_TEST_DB_URL 108 # similar tests, but using the BUILDBOT_TEST_DB_URL
154 109
155 def setUp(self): 110 def setUp(self):
156 d = self.setUpRealDatabase(want_pool=False) 111 d = self.setUpRealDatabase(want_pool=False)
157 def make_pool(_): 112 def make_pool(_):
158 self.pool = pool.DBThreadPool(self.db_engine) 113 self.pool = pool.DBThreadPool(self.db_engine)
159 d.addCallback(make_pool) 114 d.addCallback(make_pool)
160 return d 115 return d
(...skipping 21 matching lines...) Expand all
182 t = conn.begin() 137 t = conn.begin()
183 native_tests.create(bind=conn) 138 native_tests.create(bind=conn)
184 t.commit() 139 t.commit()
185 d = self.pool.do(ddl) 140 d = self.pool.do(ddl)
186 def access(conn): 141 def access(conn):
187 native_tests.insert(bind=conn).execute([ {'name':'foo'} ]) 142 native_tests.insert(bind=conn).execute([ {'name':'foo'} ])
188 d.addCallback(lambda _ : 143 d.addCallback(lambda _ :
189 self.pool.do(access)) 144 self.pool.do(access))
190 return d 145 return d
191 146
OLDNEW
« no previous file with comments | « third_party/buildbot_8_4p1/buildbot/db/pool.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698