Skip to content

Commit 758f7e6

Browse files
authored
Merge pull request #394 from rubygems/segiddins/test-full-matrix-of-supported-adapters
Test full matrix of supported adapters
2 parents 53d6769 + 829bc60 commit 758f7e6

5 files changed

Lines changed: 98 additions & 7 deletions

File tree

.github/workflows/gemstash-ci.yml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Tests
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
jobs:
610
gemstash_tests:
@@ -9,6 +13,50 @@ jobs:
913
fail-fast: false
1014
matrix:
1115
ruby: ["3.1", "3.2", "3.3", "jruby-9.4"]
16+
db_adapter: ["sqlite3"]
17+
cache_type: ["memory"]
18+
include:
19+
- ruby: "3.3"
20+
db_adapter: "postgres"
21+
cache_type: "memory"
22+
- ruby: "3.3"
23+
db_adapter: "mysql2"
24+
cache_type: "memory"
25+
- ruby: "3.3"
26+
db_adapter: "sqlite3"
27+
cache_type: "memcached"
28+
- ruby: "3.3"
29+
db_adapter: "sqlite3"
30+
cache_type: "redis"
31+
- ruby: "jruby-9.4"
32+
db_adapter: "sqlite3"
33+
cache_type: "memcached"
34+
- ruby: "jruby-9.4"
35+
db_adapter: "sqlite3"
36+
cache_type: "redis"
37+
services:
38+
postgres:
39+
image: postgres:13
40+
env:
41+
POSTGRES_USER: postgres
42+
POSTGRES_PASSWORD: postgres
43+
POSTGRES_DB: gemstash_test
44+
ports:
45+
- 5432:5432
46+
memcached:
47+
image: memcached:1.6
48+
ports:
49+
- 11211:11211
50+
redis:
51+
image: redis:7
52+
ports:
53+
- 6379:6379
54+
env:
55+
GEMSTASH_SPEC_CACHE_TYPE: ${{ matrix.cache_type }}
56+
GEMSTASH_SPEC_DB_ADAPTER: ${{ matrix.db_adapter }}
57+
GEMSTASH_SPEC_DB_URL: ${{ (matrix.db_adapter == 'postgres' && 'postgres://postgres:postgres@localhost/gemstash_test') || (matrix.db_adapter == 'mysql2' && 'mysql2://root:[email protected]:3306/gemstash_test') }}
58+
GEMSTASH_SPEC_REDIS_SERVERS: redis://localhost:6379
59+
GEMSTASH_SPEC_MEMCACHED_SERVERS: localhost:11211
1260
steps:
1361
- uses: actions/checkout@v4
1462
- name: Setup ruby
@@ -18,8 +66,29 @@ jobs:
1866
bundler-cache: true # 'bundle install' and cache
1967
- name: increase ulimit
2068
run: ulimit -n 8192
69+
- name: Set up MySQL
70+
if: matrix.db_adapter == 'mysql2'
71+
run: |
72+
set -eux
73+
sudo /etc/init.d/mysql start
74+
mysql -e 'CREATE DATABASE gemstash_test;' --user=root --password=root
75+
mysqladmin ping --user=root --password=root
2176
- name: Run Tests
2277
run: bundle exec rspec --exclude-pattern "spec/integration_spec.rb"
2378
- name: Run Integration Tests
2479
run: bundle exec rspec ./spec/integration_spec.rb
2580
timeout-minutes: 60
81+
82+
all-tests-pass:
83+
if: always()
84+
85+
needs:
86+
- gemstash_tests
87+
88+
runs-on: ubuntu-latest
89+
90+
steps:
91+
- name: check test jobs
92+
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
93+
with:
94+
jobs: ${{ toJSON(needs) }}

Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ gem "rspec", "~> 3.3"
1313
gem "webrick", "~> 1.6"
1414

1515
platform :jruby do
16+
gem "jdbc-sqlite3"
1617
gem "psych"
1718
end
1819

20+
platform :ruby do
21+
gem "mysql2"
22+
gem "pg"
23+
gem "sqlite3"
24+
end
25+
1926
group :linting do
2027
gem "rubocop", "~> 1.44"
2128
gem "rubocop-performance", "~> 1.5"

lib/gemstash/cache.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ def get(key)
101101
end
102102

103103
def get_multi(keys)
104-
@cache.mget(*keys).each do |k, v|
104+
@cache.mget(*keys).each_with_index do |v, idx|
105105
next if v.nil?
106106

107+
k = keys[idx]
107108
yield(k, YAML.load(v))
108109
end
109110
end

lib/gemstash/env.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ def db
132132
Sequel.connect("sqlite://#{CGI.escape(db_path)}", config.database_connection_config)
133133
end
134134
when "postgres", "mysql", "mysql2"
135-
db = Sequel.connect(config[:db_url], config.database_connection_config)
135+
db_url = config[:db_url]
136+
raise "Missing DB URL" unless db_url
137+
138+
db = Sequel.connect(db_url, config.database_connection_config)
136139
else
137140
raise "Unsupported DB adapter: '#{config[:db_adapter]}'"
138141
end

spec/spec_helper.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
Pathname.new(TEST_BASE_PATH).children.each(&:rmtree)
2424
TEST_LOG_FILE = File.join(TEST_BASE_PATH, "server.log")
2525
TEST_CONFIG = Gemstash::Configuration.new(config: {
26-
:base_path => TEST_BASE_PATH
26+
base_path: TEST_BASE_PATH,
27+
cache_type: ENV.fetch("GEMSTASH_SPEC_CACHE_TYPE", "memory"),
28+
db_adapter: ENV.fetch("GEMSTASH_SPEC_DB_ADAPTER", "sqlite3"),
29+
db_url: ENV.fetch("GEMSTASH_SPEC_DB_URL", nil),
30+
redis_servers: ENV.fetch("GEMSTASH_SPEC_REDIS_SERVERS", nil),
31+
memcached_servers: ENV.fetch("GEMSTASH_SPEC_MEMCACHED_SERVERS", nil)
2732
})
2833
Gemstash::Env.current = Gemstash::Env.new(TEST_CONFIG)
2934
Thread.current[:test_gemstash_env_set] = true
@@ -45,13 +50,19 @@
4550
end
4651
end
4752

48-
TEST_DB.disconnect
49-
5053
# If a spec has no transaction, delete the DB, and force recreate/migrate to ensure it is clean
5154
if example.metadata[:db_transaction] == false
52-
File.delete(File.join(TEST_BASE_PATH, "gemstash.db"))
55+
if TEST_CONFIG[:db_adapter] == "sqlite3"
56+
File.delete(File.join(TEST_BASE_PATH, "gemstash.db"))
57+
else
58+
# Drop all tables
59+
TEST_DB.drop_table(*TEST_DB.tables)
60+
end
61+
TEST_DB.disconnect
5362
Gemstash::Env.migrate(TEST_DB)
5463
end
64+
65+
TEST_DB.disconnect
5566
end
5667

5768
config.before(:each) do

0 commit comments

Comments
 (0)