Skip to content

Commit 3b43858

Browse files
authored
CI and spec maintenance (#114)
* 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
1 parent 042c5d6 commit 3b43858

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest]
16-
crystal: [1.0.0, latest, nightly]
16+
crystal: [1.3.0, latest, nightly]
1717
mysql_docker_image: ["mysql:5.6", "mysql:5.7"]
1818
runs-on: ${{ matrix.os }}
1919
steps:

spec/db_spec.cr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ DB::DriverSpecs(MySql::Any).run do |ctx|
4848

4949
DB.open db_url do |db|
5050
# needs to check version, microsecond support >= 5.7
51-
dbversion = SemanticVersion.parse(db.scalar("SELECT VERSION();").as(String))
52-
if dbversion >= SemanticVersion.new(5, 7, 0)
51+
if mysql_version(db) >= SemanticVersion.new(5, 7, 0)
5352
sample_value Time.utc(2016, 2, 15, 10, 15, 30, nanosecond: 543_000_000), "datetime(3)", "TIMESTAMP '2016-02-15 10:15:30.543'"
5453
sample_value Time.utc(2016, 2, 15, 10, 15, 30, nanosecond: 543_012_000), "datetime(6)", "TIMESTAMP '2016-02-15 10:15:30.543012'"
5554
sample_value Time.utc(2016, 2, 15, 10, 15, 30, nanosecond: 543_000_000), "timestamp(3)", "TIMESTAMP '2016-02-15 10:15:30.543'"

spec/driver_spec.cr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "./spec_helper"
2+
require "semantic_version"
23

34
def with_db(&block : DB::Database ->)
45
DB.open db_url, &block
@@ -15,8 +16,12 @@ describe Driver do
1516
db.scalar("SELECT CURRENT_USER()").should match(/^root@/)
1617

1718
# ensure user is deleted
18-
db.exec "GRANT USAGE ON *.* TO crystal_test IDENTIFIED BY 'secret'"
19-
db.exec "DROP USER crystal_test"
19+
if mysql_version(db) >= SemanticVersion.new(5, 7, 0)
20+
db.exec "DROP USER IF EXISTS crystal_test"
21+
else
22+
db.exec "GRANT USAGE ON *.* TO crystal_test IDENTIFIED BY 'secret'"
23+
db.exec "DROP USER crystal_test"
24+
end
2025
db.exec "DROP DATABASE IF EXISTS crystal_mysql_test"
2126
db.exec "FLUSH PRIVILEGES"
2227

spec/pool_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe DB::Pool do
1414
spawn do
1515
(1..max_n).each do |n|
1616
db.exec "insert into numbers (n, fiber) values (?, ?)", n, f
17-
sleep 0.01
17+
sleep 0.01.seconds
1818
end
1919
channel.send nil
2020
end
@@ -46,7 +46,7 @@ describe DB::Pool do
4646
spawn do
4747
cnn = db.checkout
4848
max_open_connections.max(db.pool.stats.open_connections)
49-
sleep 0.01
49+
sleep 0.01.seconds
5050
cnn.release
5151
channel.send nil
5252
end

spec/spec_helper.cr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "spec"
22
require "../src/mysql"
3+
require "semantic_version"
34

45
include MySql
56

@@ -23,3 +24,8 @@ ensure
2324
db.exec "DROP DATABASE IF EXISTS crystal_mysql_test"
2425
end
2526
end
27+
28+
def mysql_version(db) : SemanticVersion
29+
# some docker images might report 5.7.30-0ubuntu0.18.04.1, so we split in "-"
30+
SemanticVersion.parse(db.scalar("SELECT VERSION();").as(String).split("-").first)
31+
end

0 commit comments

Comments
 (0)