Skip to content

Commit

Permalink
Merge pull request #2461 from tardyp/sqltests
Browse files Browse the repository at this point in the history
add mysql tests
  • Loading branch information
tardyp committed Dec 7, 2016
2 parents 46f9f68 + b4d18d8 commit c3d6a40
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
17 changes: 11 additions & 6 deletions .bbtravis.yml
Expand Up @@ -29,11 +29,12 @@ env:
# Helps to detect issues with incorrect database setup/cleanup in tests.
- 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
#- 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
# 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
#- TWISTED=latest SQLALCHEMY=latest TESTS=trial 'BUILDBOT_TEST_DB_URL=postgresql+pg8000:///bbtest?user=buildbot&password=x'

# Test different versions of SQLAlchemy
- TWISTED=15.5.0 SQLALCHEMY=0.8.0 TESTS=trial
Expand Down Expand Up @@ -109,9 +110,13 @@ install:
before_script:
# create real database for tests
- condition: '"mysql" in BUILDBOT_TEST_DB_URL'
cmd: mysql -e 'create database bbtest;'
cmd: sudo /etc/init.d/mysql start
- condition: '"postgresql" in BUILDBOT_TEST_DB_URL'
cmd: psql -c 'create database bbtest;' -U postgres
cmd: |
sudo /etc/init.d/postgresql start
# for pg8000 driver we can't use peer authentication or empty password, so set a dummy password
# This also serves as a way to wait that the database is ready
while ! psql -d bbtest -c 'ALTER USER "buildbot" WITH PASSWORD '"'x'"';' ; do sleep 1 ; done
# Tests running commands
script:
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
4 changes: 2 additions & 2 deletions master/buildbot/db/model.py
Expand Up @@ -146,7 +146,7 @@ class Model(base.DBConnectorComponent):
# start/complete times
sa.Column('started_at', sa.Integer, nullable=False),
sa.Column('complete_at', sa.Integer),
sa.Column('state_string', sa.Text, nullable=False, server_default=''),
sa.Column('state_string', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
)

Expand All @@ -160,7 +160,7 @@ class Model(base.DBConnectorComponent):
sa.Column('buildid', sa.Integer, sa.ForeignKey('builds.id')),
sa.Column('started_at', sa.Integer),
sa.Column('complete_at', sa.Integer),
sa.Column('state_string', sa.Text, nullable=False, server_default=''),
sa.Column('state_string', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
sa.Column('urls_json', sa.Text, nullable=False),
sa.Column(
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/newsfragments/mysql5.bugfix
@@ -0,0 +1 @@
fix compatibility issue with mysql5 (do not set default value for TEXT column).
Expand Up @@ -41,14 +41,14 @@ def create_tables_thd(self, conn):
sa.Column('started_at', sa.Integer),
sa.Column('complete_at', sa.Integer),
sa.Column(
'state_string', sa.Text, nullable=False, server_default=''),
'state_string', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
sa.Column('urls_json', sa.Text, nullable=False),
)
steps.create()

conn.execute(steps.insert(), [
dict(number=3, name='echo', urls_json='[]')])
dict(number=3, name='echo', urls_json='[]', state_string='')])

def test_update(self):
def setup_thd(conn):
Expand Down
Expand Up @@ -79,7 +79,7 @@ def _define_old_tables(self, metadata):
sa.Column('started_at', sa.Integer, nullable=False),
sa.Column('complete_at', sa.Integer),
sa.Column(
'state_string', sa.Text, nullable=False, server_default=''),
'state_string', sa.Text, nullable=False),
sa.Column('results', sa.Integer),
)

Expand Down
1 change: 0 additions & 1 deletion master/docs/manual/cfg-global.rst
Expand Up @@ -63,7 +63,6 @@ Setting this parameter ensures that connections are closed and re-opened after t
If you see errors such as ``_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')``, this means your ``max_idle`` setting is probably too high.
``show global variables like 'wait_timeout';`` will show what the currently configured ``wait_timeout`` is on your MySQL server.

When using MySQL 5.x, if you see errors such as ``BLOB, TEXT, GEOMETRY or JSON column state_string can not have a default value`` make sure to add ``sql_mode='MYSQL40'`` in your configuration cnf file.

Buildbot requires ``use_unique=True`` and ``charset=utf8``, and will add them automatically, so they do not need to be specified in ``db_url``.

Expand Down

0 comments on commit c3d6a40

Please sign in to comment.