diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 1b799ad0c..42a8209a9 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -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 diff --git a/.github/workflows/custom/after-install/action.yml b/.github/workflows/custom/after-install/action.yml index 01ca45583..43629fc85 100644 --- a/.github/workflows/custom/after-install/action.yml +++ b/.github/workflows/custom/after-install/action.yml @@ -20,12 +20,12 @@ runs: mariadb-version: 10.9 - uses: ankane/setup-mysql@v1 - if: env.DM_TEST_SRC == 'test-mysql-maria' + if: env.DM_TEST_SRC == 'test-mysql' with: mysql-version: "8.0" - name: Create database (MariaDB), set it to UTF-8, add time zone info - if: env.DM_TEST_SRC == 'test-maria' || env.DM_TEST_SRC == 'test-mysql-maria' + if: env.DM_TEST_SRC == 'test-maria' || env.DM_TEST_SRC == 'test-mysql' run: | mysql -e "CREATE DATABASE IF NOT EXISTS test; ALTER DATABASE test CHARACTER SET 'utf8'; FLUSH PRIVILEGES;" shell: bash diff --git a/Makefile b/Makefile index 07adf2d81..08529cbcb 100644 --- a/Makefile +++ b/Makefile @@ -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}")' @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 30b039d1b..5b4443533 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,10 +6,11 @@ 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: @@ -17,6 +18,8 @@ services: MYSQL_DATABASE: test MYSQL_USER: compose MYSQL_PASSWORD: "YourStrong!Passw0rd" + volumes: + - mysql-db:/var/lib/mysql ports: - "3307:3306" maria: diff --git a/tests/testthat/helper-config-db.R b/tests/testthat/helper-config-db.R index b414656b2..6d3b08de6 100644 --- a/tests/testthat/helper-config-db.R +++ b/tests/testthat/helper-config-db.R @@ -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( diff --git a/tests/testthat/helper-sync.R b/tests/testthat/helper-sync.R index ac00e0c73..b8def43e5 100644 --- a/tests/testthat/helper-sync.R +++ b/tests/testthat/helper-sync.R @@ -19,6 +19,7 @@ local({ sources <- c( "duckdb", "maria", + "mysql", "mssql", "postgres", "sqlite", diff --git a/tests/testthat/test-mysql.R b/tests/testthat/test-mysql.R new file mode 100644 index 000000000..92b457d48 --- /dev/null +++ b/tests/testthat/test-mysql.R @@ -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()) + }) +})