hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
TESTDIR=${TESTDIR:-.}
|
2018-02-15 07:31:36 +03:00
|
|
|
GETDB_PATH="$TESTDIR/${HGTEST_GETDB_PATH:-getdb.sh}"
|
|
|
|
|
|
|
|
if [[ ! -f "$GETDB_PATH" ]]; then
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
echo "skipped: getdb.sh missing. copy from getdb.sh.example and edit it"
|
|
|
|
exit 80
|
|
|
|
fi
|
2014-01-29 08:49:56 +04:00
|
|
|
|
2017-03-25 00:01:13 +03:00
|
|
|
if ! ${PYTHON:-python} -c "import mysql.connector" 2>/dev/null; then
|
|
|
|
echo "skipped: mysql-connector-python missing"
|
|
|
|
exit 80
|
|
|
|
fi
|
|
|
|
|
2018-02-15 07:31:36 +03:00
|
|
|
source "$GETDB_PATH" >/dev/null
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
|
|
|
|
[[ -z $DBHOST ]] && DBHOST=localhost
|
|
|
|
[[ -z $DBPORT ]] && DBPORT=3306
|
2018-02-21 16:55:07 +03:00
|
|
|
[[ -z $DBENGINE ]] && DBENGINE=innodb
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
[[ -z $DBPASS && -n $PASSWORD ]] && DBPASS="$PASSWORD"
|
|
|
|
[[ -z $DBUSER && -n $USER ]] && DBUSER="$USER"
|
|
|
|
[[ -z $DBNAME ]] && DBNAME="testdb_hgsql_$$_$(date +%s)" && DBAUTODROP=1
|
|
|
|
[[ -n $DBPASS ]] && DBPASSOPT="-p$DBPASS"
|
2014-10-27 19:54:31 +03:00
|
|
|
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
MYSQLLOG="${MYSQLLOG:-/dev/null}"
|
2014-01-29 08:49:56 +04:00
|
|
|
|
2018-02-21 16:55:07 +03:00
|
|
|
# skip if DBENGINE is not supported
|
|
|
|
( mysql -h "$DBHOST" -P "$DBPORT" -u "$DBUSER" "$DBPASSOPT" \
|
|
|
|
--execute='SHOW ENGINES' --silent --skip-column-names | \
|
|
|
|
egrep -iq "^$DBENGINE[[:space:]](default|yes)[[:space:]]" )
|
|
|
|
|
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
echo "skipped: $DBENGINE unsupported"
|
|
|
|
exit 80
|
|
|
|
fi
|
|
|
|
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
mysql -h "$DBHOST" -P "$DBPORT" -u "$DBUSER" "$DBPASSOPT" &>> "$MYSQLLOG" <<EOF
|
|
|
|
CREATE DATABASE IF NOT EXISTS $DBNAME;
|
|
|
|
USE $DBNAME;
|
|
|
|
DROP TABLE IF EXISTS revisions;
|
2014-10-27 19:54:31 +03:00
|
|
|
DROP TABLE IF EXISTS revision_references;
|
2019-03-18 19:38:31 +03:00
|
|
|
DROP TABLE IF EXISTS repo_lock;
|
2018-02-21 16:55:07 +03:00
|
|
|
$(cat $TESTDIR/hgsql/schema.$DBENGINE.sql)
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
EOF
|
|
|
|
|
2017-03-25 00:01:13 +03:00
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
echo "skipped: unable to initialize the database. check your getdb.sh"
|
|
|
|
exit 80
|
|
|
|
fi
|
|
|
|
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
function droptestdb() {
|
|
|
|
mysql -h "$DBHOST" -P "$DBPORT" -u "$DBUSER" "$DBPASSOPT" &>> "$MYSQLLOG" <<EOF
|
|
|
|
DROP DATABASE $DBNAME;
|
|
|
|
EOF
|
|
|
|
}
|
2014-10-27 19:54:31 +03:00
|
|
|
|
hgsql: make it test-friendly for external users
Summary:
Previously, when running with an external MySQL setup, it's easy to get the
following "mysterious" error when trying to create the "revisions" table:
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
This is a cleanup of many minor areas to make it easier for external users
to run the test.
* Move database schema to `schema.sql`, which could be used as `mysql`
input directly. Remove schema in other places so `schema.sql` is the
single source of truth.
* Change `repo`, `namespace` fields to `varchar` to save space.
* Explicitly set `latin1(_bin)` in schema to avoid potential encoding
issues. Also specify `InnoDB` to avoid issues of other engines.
* Source `getdb.sh` instead of parsing its output. Simplifies `getdb.sh`.
* Provide an example of `getdb.sh` as `getdb.sh.example`.
* Add `DROP DATABASE` cleanup. External setup probably don't have `testdb`
dropped automatically.
* Change `README.md` with the latest instruction about database and test.
* Bundle `hg-ssh` so `test-pushpull.t` won't fail if it's missing.
Test Plan: `run-tests.py` and it mostly works on a local, non-prod Linux system.
Reviewers: #sourcecontrol, rmcelroy
Reviewed By: rmcelroy
Subscribers: stash, rmcelroy, tja, durham, andrasbelo
Differential Revision: https://phabricator.intern.facebook.com/D4313981
Signature: t1:4313981:1490381520:7c0c9af72ac3446c5ee31f8c9b4376c4198a6dc8
2017-03-24 05:14:52 +03:00
|
|
|
[[ $DBAUTODROP == 1 ]] && trap droptestdb EXIT
|
2014-01-29 08:49:56 +04:00
|
|
|
|
|
|
|
function initserver() {
|
2018-01-04 18:22:19 +03:00
|
|
|
hg init --config extensions.hgsql= $1
|
2016-04-19 08:07:07 +03:00
|
|
|
configureserver $1 $2
|
|
|
|
}
|
|
|
|
|
|
|
|
configureserver() {
|
2014-01-29 08:49:56 +04:00
|
|
|
cat >> $1/.hg/hgrc <<EOF
|
|
|
|
[extensions]
|
2018-01-04 18:22:19 +03:00
|
|
|
hgsql=
|
2014-01-29 08:49:56 +04:00
|
|
|
|
|
|
|
[hgsql]
|
|
|
|
enabled = True
|
|
|
|
host = $DBHOST
|
|
|
|
database = $DBNAME
|
2014-10-27 19:54:31 +03:00
|
|
|
user = $DBUSER
|
|
|
|
password = $DBPASS
|
2014-01-29 08:49:56 +04:00
|
|
|
port = $DBPORT
|
|
|
|
reponame = $2
|
2018-02-21 16:55:07 +03:00
|
|
|
engine = $DBENGINE
|
2014-01-29 08:49:56 +04:00
|
|
|
|
2016-12-07 03:04:20 +03:00
|
|
|
[server]
|
|
|
|
preferuncompressed=True
|
|
|
|
uncompressed=True
|
|
|
|
|
2014-01-29 08:49:56 +04:00
|
|
|
[ui]
|
|
|
|
ssh=python "$TESTDIR/dummyssh"
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function initclient() {
|
|
|
|
hg init $1
|
2016-04-19 08:07:07 +03:00
|
|
|
configureclient $1
|
|
|
|
}
|
|
|
|
|
|
|
|
configureclient() {
|
2014-01-29 08:49:56 +04:00
|
|
|
cat >> $1/.hg/hgrc <<EOF
|
|
|
|
[ui]
|
|
|
|
ssh=python "$TESTDIR/dummyssh"
|
2014-02-19 03:59:46 +04:00
|
|
|
|
|
|
|
[extensions]
|
2018-01-04 18:22:19 +03:00
|
|
|
hgsql=
|
2014-01-29 08:49:56 +04:00
|
|
|
EOF
|
|
|
|
}
|