mysql_isolated_server 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40822abde8d3de427280276886533575dbeb17a6
4
- data.tar.gz: 511e9f144e09d7f9bce84e80f1ecb12717537b46
3
+ metadata.gz: 67d72229d0517a98714dfc5deed145686d15615b
4
+ data.tar.gz: cdbcf4df767a442c2966f3bbca80c744d9faa8d2
5
5
  SHA512:
6
- metadata.gz: 36da7b3e55bf118d0cb146daf3cb38888462b6b71d4e75d2776c40eafc6daff285fbdb7367af8f254223b77da1d86c2bc84023940a2d84ffa03f7d1d05aa8f8d
7
- data.tar.gz: bd421791201d11a1e620a236a7e82e6621ee00863aa6858d55948935bf54ff05633754e64a16754e29a71f5ca889f50fad467d7dfcaf9a7c1d1f83d37849dea9
6
+ metadata.gz: 5b93073f78435f66251c6798c7ff04ad48c9ff88eed4b68e72d615499470793dfc29b111cf800cd69203b44b5ae1f2888d5b321b3b68496437d5bd351f3536cc
7
+ data.tar.gz: 68d52352a2b3dc84306eece440380dc71ea8f4e616dd3b25bd50a27abe1c26a047f4bde3ed1aa1322e3614f981313ac7e6b73b2c92f3117ffc271bc41ef049cd
@@ -1,3 +1,3 @@
1
1
  class MysqlIsolatedServer
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -162,20 +162,14 @@ class MysqlIsolatedServer
162
162
  end
163
163
 
164
164
  attr_reader :pid
165
- def exec_server(cmd)
166
- cmd.strip!
167
- cmd.gsub!(/\\\n/, ' ')
168
- devnull = File.open("/dev/null", "w")
169
- system("mkdir -p #{base}/tmp")
170
- system("chmod 0777 #{base}/tmp")
171
-
172
- parent_pid = @parent_pid || $$
173
- mysql_pid = nil
174
-
175
- middle_pid = fork do
176
- mysql_pid = fork do
177
- ENV["TMPDIR"] = "#{base}/tmp"
178
- if !@allow_output
165
+ def self.exec_wait(cmd, options = {})
166
+ allow_output = options[:allow_output] # default false
167
+ parent_pid = options[:parent_pid] || $$
168
+
169
+ fork do
170
+ exec_pid = fork do
171
+ if !allow_output
172
+ devnull = File.open("/dev/null", "w")
179
173
  STDOUT.reopen(devnull)
180
174
  STDERR.reopen(devnull)
181
175
  end
@@ -188,8 +182,12 @@ class MysqlIsolatedServer
188
182
  #
189
183
  ["TERM", "INT"].each do |sig|
190
184
  trap(sig) do
191
- Process.kill("KILL", mysql_pid) rescue nil
192
- cleanup!
185
+ if block_given?
186
+ yield(exec_pid)
187
+ else
188
+ Process.kill("KILL", exec_pid)
189
+ end
190
+
193
191
  exit!
194
192
  end
195
193
  end
@@ -197,18 +195,36 @@ class MysqlIsolatedServer
197
195
  while true
198
196
  begin
199
197
  Process.kill(0, parent_pid)
200
- Process.kill(0, mysql_pid)
198
+ Process.kill(0, exec_pid)
201
199
  rescue Exception => e
202
- Process.kill("KILL", mysql_pid)
203
- cleanup!
200
+ if block_given?
201
+ yield(exec_pid)
202
+ else
203
+ Process.kill("KILL", exec_pid)
204
+ end
205
+
204
206
  exit!
205
207
  end
206
208
 
207
209
  sleep 1
208
210
  end
209
211
  end
212
+ end
210
213
 
211
- @pid = middle_pid
214
+ def exec_server(cmd)
215
+ cmd.strip!
216
+ cmd.gsub!(/\\\n/, ' ')
217
+ system("mkdir -p #{base}/tmp")
218
+ system("chmod 0777 #{base}/tmp")
219
+
220
+ parent_pid = @parent_pid || $$
221
+ mysql_pid = nil
222
+
223
+ ENV["TMPDIR"] = "#{base}/tmp"
224
+ @pid = MysqlIsolatedServer.exec_wait(cmd, allow_output: @allow_output, parent_pid: @parent_pid) do |mysql_pid|
225
+ Process.kill("KILL", mysql_pid)
226
+ cleanup!
227
+ end
212
228
  end
213
229
 
214
230
  def mysql_shell
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_isolated_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-08 00:00:00.000000000 Z
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A small library that allows you to easily spin up new local mysql servers
14
14
  for testing purposes.