Skip to content

Commit

Permalink
fix tests for innodb engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tardyp committed Dec 7, 2016
1 parent b4d18d8 commit 510e414
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .bbtravis.yml
Expand Up @@ -30,7 +30,7 @@ env:
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=sqlite:////tmp/test_db.sqlite
# Configuration that runs tests with real MySQL database (TODO does not work yet with our docker image)
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=mysql+mysqldb://travis@127.0.0.1/bbtest
#- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=mysql+mysqldb://travis@127.0.0.1/bbtest?storage_engine=InnoDB
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=mysql+mysqldb://travis@127.0.0.1/bbtest?storage_engine=InnoDB
# Configuration that runs tests with real PostgreSQL database with pg8000 and psycopg2 drivers
# psycopg2 uses Peer Authentication which is configured in the dockerfile, while pg8000 use md5 auth with dummy password
#- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=postgresql+psycopg2:///bbtest
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -29,7 +29,7 @@ env:
# Helps to detect issues with incorrect database setup/cleanup in tests.
# Configuration that runs tests with real MySQL database
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=mysql+mysqldb://travis@127.0.0.1/bbtest
#- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=mysql+mysqldb://travis@127.0.0.1/bbtest?storage_engine=InnoDB
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=mysql+mysqldb://travis@127.0.0.1/bbtest?storage_engine=InnoDB
# Configuration that runs tests with real PostgreSQL database with pg8000 and psycopg2 drivers
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=postgresql+psycopg2:///bbtest?user=postgres
- TWISTED=latest SQLALCHEMY=latest TESTS=trial BUILDBOT_TEST_DB_URL=postgresql+pg8000:///bbtest?user=postgres
Expand Down
3 changes: 2 additions & 1 deletion master/buildbot/db/users.py
Expand Up @@ -196,7 +196,8 @@ def thd(conn):
& (tbl_info.c.attr_type == attr_type))
res = conn.execute(q, attr_data=attr_data)
if res.rowcount == 0:
_race_hook and _race_hook(conn)
if _race_hook is not None:
_race_hook(conn)

# the update hit 0 rows, so try inserting a new one
try:
Expand Down
22 changes: 16 additions & 6 deletions master/buildbot/test/unit/test_db_users.py
Expand Up @@ -12,6 +12,8 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
import sqlalchemy

from twisted.trial import unittest

from buildbot.db import users
Expand Down Expand Up @@ -431,7 +433,7 @@ def test_updateUser_race(self):
# the existing transaction) and executes a conflicting insert in that
# connection. This will cause the insert in the db method to fail, and
# the data in this insert (8.8.8.8) will appear below.

transaction_wins = []
if (self.db.pool.engine.dialect.name == 'sqlite' and
self.db.pool.engine.url.database not in [None, ':memory:']):
# It's not easy to work with file-based SQLite via multiple
Expand All @@ -443,10 +445,15 @@ def test_updateUser_race(self):

def race_thd(conn):
conn = self.db.pool.engine.connect()
conn.execute(self.db.model.users_info.insert(),
uid=1, attr_type='IPv4',
attr_data='8.8.8.8')

try:
r = conn.execute(self.db.model.users_info.insert(),
uid=1, attr_type='IPv4',
attr_data='8.8.8.8')
r.close()
except sqlalchemy.exc.OperationalError:
# some engine (mysql innodb) will enforce lock until the transaction is over
transaction_wins.append(True)
# scope variable, we modify a list so that modification is visible in parent scope
d = self.insertTestData(self.user1_rows)

def update1(_):
Expand All @@ -461,7 +468,10 @@ def get1(_):

def check1(usdict):
self.assertEqual(usdict['identifier'], 'soap')
self.assertEqual(usdict['IPv4'], '8.8.8.8')
if transaction_wins:
self.assertEqual(usdict['IPv4'], '123.134.156.167')
else:
self.assertEqual(usdict['IPv4'], '8.8.8.8')
self.assertEqual(usdict['IPv9'], '0578cc6.8db024') # no change
d.addCallback(check1)
return d
Expand Down

0 comments on commit 510e414

Please sign in to comment.