Skip to content

Commit

Permalink
CI and spec maintenance (#114)
Browse files Browse the repository at this point in the history
* Fix deprecation warnings in specs

* Extract mysql_version

* Use DROP USER IF EXISTS when available

mysql 8.0 was failing on the workaround

* Bump minimal crystal version in CI due to openssl 3.0.0
  • Loading branch information
bcardiff authored Dec 23, 2024
1 parent 042c5d6 commit 3b43858
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions spec/db_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
9 changes: 7 additions & 2 deletions spec/driver_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "./spec_helper"
require "semantic_version"

def with_db(&block : DB::Database ->)
DB.open db_url, &block
Expand All @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions spec/pool_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "spec"
require "../src/mysql"
require "semantic_version"

include MySql

Expand All @@ -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

0 comments on commit 3b43858

Please sign in to comment.