Skip to content

Commit

Permalink
Add mysql source
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 30, 2023
1 parent e689685 commit 529d8db
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ jobs:
- {os: ubuntu-20.04, r: 'release', test-src: 'test-mssql', covr: false, desc: 'SQL Server without covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-postgres', covr: true, desc: 'Postgres with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-maria', covr: true, desc: 'MariaDB with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-mysql-maria', covr: true, desc: 'MySQL with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-mysql', covr: true, desc: 'MySQL with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-duckdb', covr: true, desc: 'DuckDB with covr' }
- {os: ubuntu-22.04, r: 'release', test-src: 'test-sqlite', covr: true, desc: 'SQLite with covr' }
# End custom: matrix elements
Expand Down
26 changes: 18 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ all: qtest
# Quiet tests
# Run with make -j $(nproc) -O
# or with pmake
qtest: qtest-df qtest-sqlite qtest-postgres qtest-mssql qtest-duckdb qtest-maria
qtest: qtest-df qtest-sqlite qtest-postgres qtest-mssql qtest-duckdb qtest-maria qtest-mysql

# Progress tests
test: test-df test-sqlite test-postgres test-mssql test-duckdb test-maria
test: test-df test-sqlite test-postgres test-mssql test-duckdb test-maria test-mysql

# Testing with lazytest
ltest: ltest-df ltest-sqlite ltest-postgres ltest-mssql ltest-duckdb ltest-maria
ltest: ltest-df ltest-sqlite ltest-postgres ltest-mssql ltest-duckdb ltest-maria ltest-mysql

# Silent testing
stest: stest-df stest-sqlite stest-postgres stest-mssql stest-duckdb stest-maria
stest: stest-df stest-sqlite stest-postgres stest-mssql stest-duckdb stest-maria stest-mysql

# Connectivity tests
connect: connect-sqlite connect-postgres connect-mssql connect-duckdb connect-maria
connect: connect-sqlite connect-postgres connect-mssql connect-duckdb connect-maria connect-mysql

qtest-%:
DM_TEST_SRC=$@ time R -q -e 'options("crayon.enabled" = TRUE); Sys.setenv(TESTTHAT_PARALLEL = FALSE); testthat::test_local(filter = "${DM_TEST_FILTER}")'
Expand All @@ -32,10 +32,20 @@ ltest-%:
connect-%:
DM_TEST_SRC=$@ R -q -e 'suppressMessages(pkgload::load_all()); my_test_con()'

db-init-maria:
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_maria(root = TRUE)$$con, "GRANT ALL ON *.* TO '"'"'compose'"'"'@'"'"'%'"'"';"); DBI::dbExecute(test_src_maria()$$con, "FLUSH PRIVILEGES")'; do sleep 1; done

db-init-mysql:
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mysql(root = TRUE)$$con, "GRANT ALL ON *.* TO '"'"'compose'"'"'@'"'"'%'"'"';"); DBI::dbExecute(test_src_mysql()$$con, "FLUSH PRIVILEGES")'; do sleep 1; done

db-init-mssql:
while ! R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mssql(FALSE)$$con, "CREATE DATABASE test")'; do sleep 1; done

db-init: db-init-maria db-init-mysql db-init-mssql

db-start:
docker-compose up -d --force-recreate
R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_maria(root = TRUE)$$con, "GRANT ALL ON *.* TO '"'"'compose'"'"'@'"'"'%'"'"';"); DBI::dbExecute(test_src_maria()$$con, "FLUSH PRIVILEGES")'
R -q -e 'suppressMessages(pkgload::load_all()); DBI::dbExecute(test_src_mssql(FALSE)$$con, "CREATE DATABASE test")'
docker-compose up -d --force-recreate --wait
$(MAKE) db-init

db-restart:
docker-compose up -d
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ volumes:
driver: local
maria-db:
driver: local
mysql-db:
driver: local
services:
# https://www.beekeeperstudio.io/blog/how-to-use-mariadb-with-docker
mysql:
# FIXME: Still need to add Makefile rules to provision MySQL database
container_name: mysql
image: mysql
environment:
MYSQL_ROOT_PASSWORD: "YourStrong!Passw0rd"
MYSQL_DATABASE: test
MYSQL_USER: compose
MYSQL_PASSWORD: "YourStrong!Passw0rd"
volumes:
- mysql-db:/var/lib/mysql
ports:
- "3307:3306"
maria:
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/helper-config-db.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ test_src_maria <- function(root = FALSE) {
dbplyr::src_dbi(con, auto_disconnect = TRUE)
}

test_src_mysql <- function(root = FALSE) {
if (Sys.getenv("DM_TEST_DOCKER_HOST") != "") {
con <- DBI::dbConnect(
RMariaDB::MariaDB(),
host = Sys.getenv("DM_TEST_DOCKER_HOST"),
username = if (root) "root" else "compose",
password = "YourStrong!Passw0rd",
dbname = "test",
port = 3307,
mysql = TRUE
)
} else {
con <- DBI::dbConnect(RMariaDB::MariaDB(), dbname = "test", mysql = TRUE)
}
dbplyr::src_dbi(con, auto_disconnect = TRUE)
}

test_src_mssql <- function(database = TRUE) {
if (Sys.getenv("DM_TEST_DOCKER_HOST") != "") {
con <- DBI::dbConnect(
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/helper-sync.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local({
sources <- c(
"duckdb",
"maria",
"mysql",
"mssql",
"postgres",
"sqlite",
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/test-mysql.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("dummy", {
expect_snapshot({
"dummy"
})
})

test_that("dm_sql()", {
# Need skip in every test block, unfortunately
skip_if_src_not("mysql")

# https://github.com/tidyverse/dbplyr/pull/1190
skip_if(is(my_test_con(), "MySQLConnection") && packageVersion("dbplyr") < "2.4.0")

expect_snapshot({
dm_for_filter_df() %>%
dm_sql(my_test_con())
})

expect_snapshot({
dm(x = data.frame(a = strrep("x", 300))) %>%
dm_sql(my_test_con())
})

expect_snapshot({
dm(x = data.frame(a = strrep("x", 10000))) %>%
dm_sql(my_test_con())
})
})

0 comments on commit 529d8db

Please sign in to comment.