mysql_framework 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mysql_framework/connector.rb +3 -2
- data/lib/mysql_framework/version.rb +1 -1
- data/spec/lib/mysql_framework/connector_spec.rb +38 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94c25e3c9a25a0ecd4c51807bb1c5906b44ac526af023445e4c6411d057b764a
|
4
|
+
data.tar.gz: 428bf47cf5598c9c5c14593447e329685f3c52af39a45e45e92b18215bdc5323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c3d58636754dfb8414caf2860b1c02c50d866a32d2c4610a2ff6e3779222bf567bb0779cbc4809555303b4477331f27e967f3b3dc80d0e7e86a1277256e7b82
|
7
|
+
data.tar.gz: 82d72de51ec32da66e77f793a813af8f8da1f074916c77fc40d30f2cda9dfac6e1756669668595405e89ff92091ef87cb1765a9f72259613b03c167f19eecbda
|
@@ -38,8 +38,7 @@ module MysqlFramework
|
|
38
38
|
def check_out
|
39
39
|
client = @connection_pool.pop(true)
|
40
40
|
|
41
|
-
|
42
|
-
client = new_client if client.closed?
|
41
|
+
client.ping if @options[:reconnect]
|
43
42
|
|
44
43
|
client
|
45
44
|
rescue ThreadError
|
@@ -56,6 +55,8 @@ module MysqlFramework
|
|
56
55
|
|
57
56
|
# This method is called to check a client back in to the connection when no longer needed.
|
58
57
|
def check_in(client)
|
58
|
+
client = new_client if client.closed?
|
59
|
+
|
59
60
|
@connection_pool.push(client)
|
60
61
|
end
|
61
62
|
|
@@ -23,7 +23,7 @@ describe MysqlFramework::Connector do
|
|
23
23
|
reconnect: false
|
24
24
|
}
|
25
25
|
end
|
26
|
-
let(:client) { double(close: true, closed?: false) }
|
26
|
+
let(:client) { double(close: true, ping: true, closed?: false) }
|
27
27
|
let(:gems) { MysqlFramework::SqlTable.new('gems') }
|
28
28
|
let(:existing_client) { Mysql2::Client.new(default_options) }
|
29
29
|
|
@@ -88,19 +88,36 @@ describe MysqlFramework::Connector do
|
|
88
88
|
it 'returns a client instance from the pool' do
|
89
89
|
expect(subject.check_out).to eq(client)
|
90
90
|
end
|
91
|
-
end
|
92
91
|
|
93
|
-
|
94
|
-
|
92
|
+
context 'and :reconnect is set to true' do
|
93
|
+
let(:options) do
|
94
|
+
{
|
95
|
+
host: ENV.fetch('MYSQL_HOST'),
|
96
|
+
port: ENV.fetch('MYSQL_PORT'),
|
97
|
+
database: "#{ENV.fetch('MYSQL_DATABASE')}_2",
|
98
|
+
username: ENV.fetch('MYSQL_USERNAME'),
|
99
|
+
password: ENV.fetch('MYSQL_PASSWORD'),
|
100
|
+
reconnect: true
|
101
|
+
}
|
102
|
+
end
|
95
103
|
|
96
|
-
|
97
|
-
|
98
|
-
|
104
|
+
subject { described_class.new(options) }
|
105
|
+
|
106
|
+
it 'pings the server to force a reconnect' do
|
107
|
+
expect(client).to receive(:ping)
|
108
|
+
|
109
|
+
subject.check_out
|
110
|
+
end
|
99
111
|
end
|
100
112
|
|
101
|
-
|
102
|
-
|
103
|
-
|
113
|
+
context 'and :reconnect is set to false' do
|
114
|
+
subject { described_class.new(options) }
|
115
|
+
|
116
|
+
it 'pings the server to force a reconnect' do
|
117
|
+
expect(client).not_to receive(:ping)
|
118
|
+
|
119
|
+
subject.check_out
|
120
|
+
end
|
104
121
|
end
|
105
122
|
end
|
106
123
|
|
@@ -139,6 +156,17 @@ describe MysqlFramework::Connector do
|
|
139
156
|
|
140
157
|
subject.check_in(client)
|
141
158
|
end
|
159
|
+
|
160
|
+
context 'when the connection has been closed by the server' do
|
161
|
+
let(:closed_client) { double(close: true, closed?: true) }
|
162
|
+
|
163
|
+
it 'instantiates a new connection and returns it' do
|
164
|
+
expect(Mysql2::Client).to receive(:new).with(default_options).and_return(client)
|
165
|
+
expect(subject.connections).to receive(:push).with(client)
|
166
|
+
|
167
|
+
subject.check_in(closed_client)
|
168
|
+
end
|
169
|
+
end
|
142
170
|
end
|
143
171
|
|
144
172
|
describe '#with_client' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|