diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e70852e..fd52a57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - crystal: [1.0.0, latest, nightly] + crystal: [1.3.0, latest, nightly] mysql_docker_image: ["mysql:5.6", "mysql:5.7"] runs-on: ${{ matrix.os }} steps: diff --git a/spec/db_spec.cr b/spec/db_spec.cr index 6545b15..e764f54 100644 --- a/spec/db_spec.cr +++ b/spec/db_spec.cr @@ -48,8 +48,7 @@ DB::DriverSpecs(MySql::Any).run do |ctx| DB.open db_url do |db| # needs to check version, microsecond support >= 5.7 - dbversion = SemanticVersion.parse(db.scalar("SELECT VERSION();").as(String)) - if dbversion >= SemanticVersion.new(5, 7, 0) + if mysql_version(db) >= SemanticVersion.new(5, 7, 0) sample_value Time.utc(2016, 2, 15, 10, 15, 30, nanosecond: 543_000_000), "datetime(3)", "TIMESTAMP '2016-02-15 10:15:30.543'" sample_value Time.utc(2016, 2, 15, 10, 15, 30, nanosecond: 543_012_000), "datetime(6)", "TIMESTAMP '2016-02-15 10:15:30.543012'" sample_value Time.utc(2016, 2, 15, 10, 15, 30, nanosecond: 543_000_000), "timestamp(3)", "TIMESTAMP '2016-02-15 10:15:30.543'" diff --git a/spec/driver_spec.cr b/spec/driver_spec.cr index adc369e..0a13ae3 100644 --- a/spec/driver_spec.cr +++ b/spec/driver_spec.cr @@ -1,4 +1,5 @@ require "./spec_helper" +require "semantic_version" def with_db(&block : DB::Database ->) DB.open db_url, &block @@ -15,8 +16,12 @@ describe Driver do db.scalar("SELECT CURRENT_USER()").should match(/^root@/) # ensure user is deleted - db.exec "GRANT USAGE ON *.* TO crystal_test IDENTIFIED BY 'secret'" - db.exec "DROP USER crystal_test" + if mysql_version(db) >= SemanticVersion.new(5, 7, 0) + db.exec "DROP USER IF EXISTS crystal_test" + else + db.exec "GRANT USAGE ON *.* TO crystal_test IDENTIFIED BY 'secret'" + db.exec "DROP USER crystal_test" + end db.exec "DROP DATABASE IF EXISTS crystal_mysql_test" db.exec "FLUSH PRIVILEGES" diff --git a/spec/pool_spec.cr b/spec/pool_spec.cr index fbe697b..f0e99ec 100644 --- a/spec/pool_spec.cr +++ b/spec/pool_spec.cr @@ -14,7 +14,7 @@ describe DB::Pool do spawn do (1..max_n).each do |n| db.exec "insert into numbers (n, fiber) values (?, ?)", n, f - sleep 0.01 + sleep 0.01.seconds end channel.send nil end @@ -46,7 +46,7 @@ describe DB::Pool do spawn do cnn = db.checkout max_open_connections.max(db.pool.stats.open_connections) - sleep 0.01 + sleep 0.01.seconds cnn.release channel.send nil end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index e93b813..8493f18 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -1,5 +1,6 @@ require "spec" require "../src/mysql" +require "semantic_version" include MySql @@ -23,3 +24,8 @@ ensure db.exec "DROP DATABASE IF EXISTS crystal_mysql_test" end end + +def mysql_version(db) : SemanticVersion + # some docker images might report 5.7.30-0ubuntu0.18.04.1, so we split in "-" + SemanticVersion.parse(db.scalar("SELECT VERSION();").as(String).split("-").first) +end