Skip to content

Split testing into its own project #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ trim_trailing_whitespace=true
insert_final_newline=true
end_of_line=lf
charset=utf-8

[*.yml]
indent_style=space
indent_size=2
3 changes: 3 additions & 0 deletions .github/workflows/dub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ on:
schedule:
- cron: '30 7 1 * *'
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
build:
Expand Down
115 changes: 65 additions & 50 deletions .github/workflows/integration-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ on:
schedule:
- cron: '30 7 1 * *'
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
# mysql8-tests:
Expand Down Expand Up @@ -41,37 +44,37 @@ jobs:
# --health-retries 4

# steps:
# - uses: actions/checkout@v2

# - name: Install ${{ matrix.compiler }}
# uses: dlang-community/setup-dlang@v1
# with:
# compiler: ${{ matrix.compiler }}

# - name: Install dependencies on Ubuntu
# if: startsWith(matrix.os, 'ubuntu')
# run: sudo apt-get update && sudo apt-get install libevent-dev -y

# ## Turns out the unittest-vibe-ut tried to connect to an actualy MySQL on 172.18.0.1 so it's not
# ## actually a unit test at all. It's an integration test and should be pulled out from the main
# ## codebase into a separate sub module
# - name: Run unittest-vibe-ut
# env:
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
# run: |
# echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
# dub run -c unittest-vibe-ut -- -t

# - name: Build The Example Project
# working-directory: ./examples/homePage
# run: dub build

# - name: Run Example (MySQL 8)
# working-directory: ./examples/homePage
# env:
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
# run: |
# ./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
# - uses: actions/checkout@v2

# - name: Install ${{ matrix.compiler }}
# uses: dlang-community/setup-dlang@v1
# with:
# compiler: ${{ matrix.compiler }}

# - name: Set up test connection string
# env:
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
# run: |
# echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt

# - name: Run unittests with Vibe.d
# run: |
# dub run ":integration-tests-vibe"

# - name: Run unittests with Phobos
# run: |
# dub run ":integration-tests-phobos"

# - name: Build The Example Project
# working-directory: ./examples/homePage
# run: dub build

# - name: Run Example (MySQL 8)
# working-directory: ./examples/homePage
# env:
# MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
# run: |
# ./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"

mysql57-tests:
name: MySQL 5.7 Tests ${{ matrix.compiler }}
Expand Down Expand Up @@ -113,19 +116,25 @@ jobs:
with:
compiler: ${{ matrix.compiler }}

- name: Install dependencies on Ubuntu
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get update && sudo apt-get install libevent-dev -y

## Turns out the unittest-vibe-ut tried to connect to an actualy MySQL on 172.18.0.1 so it's not
## actually a unit test at all. It's an integration test and should be pulled out from the main
## codebase into a separate sub module
- name: Run unittest-vibe-ut
- name: Set up test connection string
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
dub run -c unittest-vibe-ut -- -t

- name: Run unittests with Vibe.d
run: |
dub run ":integration-tests-vibe"

- name: Run unittests with Phobos
run: |
dub run ":integration-tests-phobos"

- name: Run test connection utility
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
dub run ":testconn" -- "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"

- name: Build The Example Project
working-directory: ./examples/homePage
Expand Down Expand Up @@ -178,19 +187,25 @@ jobs:
with:
compiler: ${{ matrix.compiler }}

- name: Install dependencies on Ubuntu
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get update && sudo apt-get install libevent-dev -y

## Turns out the unittest-vibe-ut tried to connect to an actualy MySQL on 172.18.0.1 so it's not
## actually a unit test at all. It's an integration test and should be pulled out from the main
## codebase into a separate sub module
- name: Run unittest-vibe-ut
- name: Set up test connection string
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
echo "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb" > testConnectionStr.txt
dub run -c unittest-vibe-ut -- -t

- name: Run unittests with Vibe.d
run: |
dub run ":integration-tests-vibe"

- name: Run unittests with Phobos
run: |
dub run ":integration-tests-phobos"

- name: Run test connection utility
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
dub run ":testconn" -- "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"

- name: Build The Example Project
working-directory: ./examples/homePage
Expand All @@ -201,4 +216,4 @@ jobs:
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
./example "host=localhost;port=$MYSQL_PORT;user=testuser;pwd=passw0rd;db=testdb"
50 changes: 36 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ MySQL native
[![GitHub - Builds](https://github.com/mysql-d/mysql-native/actions/workflows/dub.yml/badge.svg)](https://github.com/mysql-d/mysql-native/actions/workflows/dub.yml)
[![GitHub - Integration Tests](https://github.com/mysql-d/mysql-native/actions/workflows/integration-testing.yml/badge.svg)](https://github.com/mysql-d/mysql-native/actions/workflows/integration-testing.yml)

*NOTE: we are in the process of migrating to github actions. Documentation will
eventually be generated using github actions, and stored on github. This README
is in flux at the moment, and may contain outdated information*

A [Boost-licensed](http://www.boost.org/LICENSE_1_0.txt) native [D](http://dlang.org)
client driver for MySQL and MariaDB.

Expand Down Expand Up @@ -89,7 +93,7 @@ void main(string[] args)
"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?",
"Bob", "Bobby");
bobs.close(); // Skip them

Row[] rs = conn.query( // Same SQL as above, but only prepared once and is reused!
"SELECT * FROM `tablename` WHERE `name`=? OR `name`=?",
"Bob", "Ann").array; // Get ALL the rows at once
Expand Down Expand Up @@ -119,26 +123,41 @@ Additional notes

This requires MySQL server v4.1.1 or later, or a MariaDB server. Older
versions of MySQL server are obsolete, use known-insecure authentication,
and are not supported by this package.
and are not supported by this package. Currently the github actions tests use
MySQL 5.7 and MariaDB 10. MySQL 8 is supported with `mysql_native_password`
authentication, but is not currently tested. Expect this to change in the future.

Normally, MySQL clients connect to a server on the same machine via a Unix
socket on *nix systems, and through a named pipe on Windows. Neither of these
conventions is currently supported. TCP is used for all connections.

For historical reference, see the [old homepage](http://britseyeview.com/software/mysqln/)
for the original release of this project. Note, however, that version has
become out-of-date.
Unfortunately, the original home page of Steve Teale's mysqln is no longer
available. You can see an archive on the [Internet Archive wayback
machine](https://web.archive.org/web/20120323165808/http://britseyeview.com/software/mysqln)

Developers - How to run the test suite
--------------------------------------

This package contains various unittests and integration tests. To run them,
run `run-tests`.
Unittests that do not require an actual server are located in the library
codebase. You can run just these tests using `dub test`.

Unittests that require a working server are all located in the
[integration-tests](integration-tests) subpackage. Due to a [dub
issue](https://github.com/dlang/dub/issues/2136), the integration tests are run
using the [integration-tests-phobos](integration-tests-phobos) and
[integration-tests-vibe](integration-tests-vibe) subpackages. At some point, if this dub issue
is fixed, they will simply become configurations in the main integration-tests
repository. You can run these directly from the main repository folder by
issuing the commands:

```sh
dub run :integration-tests-phobos
dub run :integration-tests-vibe
```
This will also run the library tests as well as the integration tests.

The first time you run `run-tests`, it will automatically create a
file `testConnectionStr.txt` in project's base diretory and then exit.
This file is deliberately not contained in the source repository
because it's specific to your system.
The first time you run an integration test, the file `testConnectionStr.txt`
will be created in your current directory

Open the `testConnectionStr.txt` file and verify the connection settings
inside, modifying them as needed, and if necessary, creating a test user and
Expand All @@ -148,6 +167,9 @@ The tests will completely clobber anything inside the db schema provided,
but they will ONLY modify that one db schema. No other schema will be
modified in any way.

After you've configured the connection string, run `run-tests` again
and their tests will be compiled and run, first using Phobos sockets,
then using Vibe sockets.
After you've configured the connection string, run the integration tests again.

The integration tests use
[unit-threaded](https://code.dlang.org/packages/unit-threaded) which allows for
running individual named tests. Use this for running specific tests instead of
the whole suite.
57 changes: 7 additions & 50 deletions dub.sdl
Original file line number Diff line number Diff line change
@@ -1,65 +1,22 @@
name "mysql-native"
description "A native MySQL driver implementation based on Steve Teale's original"
license "BSL-1.0"
copyright "Copyright (c) 2011-2019 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, and Nick Sabalausky"
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky"
copyright "Copyright (c) 2011-2021 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, Nick Sabalausky, and Steven Schveighoffer"
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky" "Steven Schveighoffer"

dependency "vibe-core" version="~>1.16.0" optional=true

toolchainRequirements frontend=">=2.068"

sourcePaths "source/"
importPaths "source/"

configuration "application" {
targetType "executable"
versions "VibeCustomMain"
}
subPackage "./integration-tests"
subPackage "./integration-tests-vibe"
subPackage "./integration-tests-phobos"
subPackage "./testconn"

configuration "library" {
targetType "library"
excludedSourceFiles "source/app.d"
}

// Do not use this. Use "run_tests" insetad.
configuration "unittest" {
excludedSourceFiles "source/app.d"
preBuildCommands \
"echo \"ERROR: Don't use 'dub test' to test mysql-native. Use 'run_tests' instead.\"" \
"echo Bailing..." \
"mkdir" // Generate error to halt build
}

// Run with: dub test -c unittest-vibe
configuration "unittest-vibe" {
targetType "executable"
targetPath "bin/"
targetName "mysqln-tests-vibe"
excludedSourceFiles "source/app.d"

dependency "vibe-core" version="~>1.16.0" optional=false

// mainSourceFile "source/mysql/package.d"
debugVersions "MYSQLN_TESTS"
}

// Run with: dub run -c unittest-vibe-ut -- -t
configuration "unittest-vibe-ut" {
targetType "executable"
targetPath "bin/"
targetName "mysqln-tests-vibe"
excludedSourceFiles "source/app.d"
sourceFiles "bin/ut.d"
importPaths "bin/"
buildOptions "unittests"

dependency "vibe-core" version="~>1.16.0" optional=false

dependency "unit-threaded" version="~>1.0.15"

debugVersions "MYSQLN_TESTS"
versions "MYSQLN_TESTS_NO_MAIN"
versions "unitUnthreaded"

preBuildCommands "dub run unit-threaded -c gen_ut_main -- -f bin/ut.d"
targetType "sourceLibrary"
}
8 changes: 8 additions & 0 deletions integration-tests-phobos/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name "integration-tests-phobos"
description "Phobos tests for mysql-native"
license "BSL-1.0"
copyright "Copyright (c) 2011-2021 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, Nick Sabalausky, and Steven Schveighoffer"
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky" "Steven Schveighoffer"

dependency "mysql-native:integration-tests" path="../"
targetType "executable"
Empty file.
9 changes: 9 additions & 0 deletions integration-tests-vibe/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name "integration-tests-vibe"
description "Vibe tests for mysql-native"
license "BSL-1.0"
copyright "Copyright (c) 2011-2021 Steve Teale, James W. Oliphant, Simen Endsjø, Sönke Ludwig, Sergey Shamov, Nick Sabalausky, and Steven Schveighoffer"
authors "Steve Teale" "James W. Oliphant" "Simen Endsjø" "Sönke Ludwig" "Sergey Shamov" "Nick Sabalausky" "Steven Schveighoffer"

dependency "mysql-native:integration-tests" path="../"
dependency "vibe-core" version="~>1.16.0"
targetType "executable"
Empty file.
22 changes: 22 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Integration Tests for MySQL Native
==================================

This sub-project is intended for proving the functionality of the project against a database instance.

See the instructions in the [main README](../README.md#developers---how-to-run-the-test-suite) on how to use this subpackage.

## Docker image

A docker-compose.yml is supplied for convenience when testing locally. It's preconfigured to use the same username/password that is used by default.

To run tests on your machine, presuming docker is installed, simply run:

```
$ docker-compose up --detach
```

Once you are finished, tear down the docker instance

```
$ docker-compose down
```
12 changes: 12 additions & 0 deletions integration-tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.7'
services:
mysql:
# Don't use latest (MySQL Server 8.0) as we cannot currently support it
image: mysql:5.7
restart: always
ports: ['3306:3306']
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=mysqln_testdb
- MYSQL_USER=mysqln_test
- MYSQL_PASSWORD=pass123
Loading