From 13968d62f4d618cb1db9cf6d771de0a918fc71b0 Mon Sep 17 00:00:00 2001 From: Taylor Bantle Date: Wed, 8 Mar 2023 13:35:32 -0800 Subject: [PATCH] mysql-client-tests: Write script/README for running node tests without installing everything --- .../mysql-client-tests/helpers.bash | 41 +++++++++++++++++++ .../mysql-client-tests.bats | 40 +++--------------- .../mysql-client-tests/node/README.md | 32 +++++++++++++++ .../mysql-client-tests/node/run-tests.sh | 8 ++++ 4 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 integration-tests/mysql-client-tests/helpers.bash create mode 100644 integration-tests/mysql-client-tests/node/README.md create mode 100644 integration-tests/mysql-client-tests/node/run-tests.sh diff --git a/integration-tests/mysql-client-tests/helpers.bash b/integration-tests/mysql-client-tests/helpers.bash new file mode 100644 index 0000000000..be4cb92f5a --- /dev/null +++ b/integration-tests/mysql-client-tests/helpers.bash @@ -0,0 +1,41 @@ + +setup_dolt_repo() { + REPO_NAME="dolt_repo_$$" + mkdir $REPO_NAME + cd $REPO_NAME + + dolt init + + dolt sql -q "CREATE TABLE mysqldump_table(pk int)" + dolt sql -q "INSERT INTO mysqldump_table VALUES (1);" + dolt sql -q "CREATE TABLE warehouse(warehouse_id int primary key, warehouse_name longtext)" + dolt sql -q "INSERT into warehouse VALUES (1, 'UPS'), (2, 'TV'), (3, 'Table');" + + PORT=$( definePORT ) + USER="dolt" + dolt sql-server --host 0.0.0.0 --port=$PORT --user=$USER --loglevel=trace & + SERVER_PID=$! + # Give the server a chance to start + sleep 1 + + export MYSQL_PWD="" +} + +teardown_dolt_repo() { + kill $SERVER_PID + rm -rf $REPO_NAME +} + +definePORT() { + getPORT="" + for i in {0..9} + do + let getPORT="($$ + $i) % (65536-1024) + 1024" + portinuse=$(lsof -i -P -n | grep LISTEN | grep $attemptedPORT | wc -l) + if [ $portinuse -eq 0 ] + then + echo "$getPORT" + break + fi + done +} \ No newline at end of file diff --git a/integration-tests/mysql-client-tests/mysql-client-tests.bats b/integration-tests/mysql-client-tests/mysql-client-tests.bats index 8688331a20..0230de8536 100644 --- a/integration-tests/mysql-client-tests/mysql-client-tests.bats +++ b/integration-tests/mysql-client-tests/mysql-client-tests.bats @@ -1,3 +1,6 @@ +#!/usr/bin/env bats +load $BATS_TEST_DIRNAME/helpers.bash + # MySQL client tests are set up to test Dolt as a MySQL server and # standard MySQL Clients in a wide array of languages. I used BATS because # it was easy to set up the Dolt piece using the command line. @@ -8,31 +11,12 @@ # gotchas, we can add tests for that specific language. setup() { - REPO_NAME="dolt_repo_$$" - mkdir $REPO_NAME - cd $REPO_NAME - - dolt init - - dolt sql -q "CREATE TABLE mysqldump_table(pk int)" - dolt sql -q "INSERT INTO mysqldump_table VALUES (1);" - dolt sql -q "CREATE TABLE warehouse(warehouse_id int primary key, warehouse_name longtext)" - dolt sql -q "INSERT into warehouse VALUES (1, 'UPS'), (2, 'TV'), (3, 'Table');" - - PORT=$( definePORT ) - USER="dolt" - dolt sql-server --host 0.0.0.0 --port=$PORT --user=$USER --loglevel=trace & - SERVER_PID=$! - # Give the server a chance to start - sleep 1 - - export MYSQL_PWD="" + setup_dolt_repo } teardown() { cd .. - kill $SERVER_PID - rm -rf $REPO_NAME + teardown_dolt_repo # Check if postgresql is still running. If so stop it active=$(service postgresql status) @@ -172,16 +156,4 @@ EOF" -m "postgres" Rscript $BATS_TEST_DIRNAME/r/rmariadb-test.r $USER $PORT $REPO_NAME } -definePORT() { - getPORT="" - for i in {0..9} - do - let getPORT="($$ + $i) % (65536-1024) + 1024" - portinuse=$(lsof -i -P -n | grep LISTEN | grep $attemptedPORT | wc -l) - if [ $portinuse -eq 0 ] - then - echo "$getPORT" - break - fi - done -} + diff --git a/integration-tests/mysql-client-tests/node/README.md b/integration-tests/mysql-client-tests/node/README.md new file mode 100644 index 0000000000..39824e909f --- /dev/null +++ b/integration-tests/mysql-client-tests/node/README.md @@ -0,0 +1,32 @@ +# Node Client Integration Tests + +## Install + +``` +$ npm install +``` + +## Run node tests + +To run the node tests, you must make sure you have Dolt installed on your computer and +have run `npm install`. Then update your Dolt config by running: + +```shell +sh ../mysql-client-tests-entrypoint.sh +``` + +And then you can run the tests using the `run-tests.sh` script, which sets up the database, runs the SQL server, runs the provided `.js` test file against the running server, and then tears down the database. + +For example, you can run the `workbench.js` tests by running: + +```shell +sh run-tests.sh workbench.js +``` + +## Workbench stability tests + +The tests in `workbenchTests` were written to enforce the stability of the SQL workbench +on [Hosted](https://hosted.doltdb.com/). The workbench uses many Dolt system tables, +functions, and procedures, and any changes to these interfaces can break the workbench. +@tbantle22 will be tagged in any GitHub PR that updates those files to ensure appropriate +workbench updates are made for Dolt changes that break these queries. diff --git a/integration-tests/mysql-client-tests/node/run-tests.sh b/integration-tests/mysql-client-tests/node/run-tests.sh new file mode 100644 index 0000000000..536c16755b --- /dev/null +++ b/integration-tests/mysql-client-tests/node/run-tests.sh @@ -0,0 +1,8 @@ +#!/bin/sh +source ../helpers.bash + +echo "Running $1 tests" +setup_dolt_repo +cd .. +node $1 $USER $PORT $REPO_NAME +teardown_dolt_repo \ No newline at end of file