riak_test_server 1.1.0 → 1.1.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: 0cc589b4f686c3f38244df43e45f1f08ef96e231
4
- data.tar.gz: 51c600a90c4c13e29e79a1bf9c9acd864e2d80ac
3
+ metadata.gz: 26aee048f49421dff9f93e39d5037e705fb20992
4
+ data.tar.gz: a6822d14361536f8a50b8dd1c5a0d5cb1a493cda
5
5
  SHA512:
6
- metadata.gz: b1675cd7edcb1ec9f00e440641539b32dad914cf92cd307b6b514c8f2fc767ae854a53ba3c3f529109f531edbc41cee67812b1bc96eb2fd528f7cd71f85a1279
7
- data.tar.gz: 08af4d885569903f31398ec7d58443787bec317eeda854726cfd59de1c11dd34899f2abf66469039b9e7d06bbb1ed0e6e950cc986109fe9ded07468fbc3f124d
6
+ metadata.gz: f51252686c65c863fb5d5f2289e84aae57ce9a5f5e588290587af0d1d06a21910932919668082546ae3d240064cd6fa56da2356932ba95a16f82925ee4a59d2a
7
+ data.tar.gz: 4ffb03b6f2d3947d2f3849f58de24173282486b115d6d9b9a52629fc8ba9f6b6f64585dc16ca73a5ace2d02b31befd3731b0e1ef91f2fed9e5d25f629d893e9e
data/README.md CHANGED
@@ -11,6 +11,7 @@ the Riak backend inbetween tests.
11
11
  * [docker](https://docs.docker.com/installation/)
12
12
  * A working docker host environment (I like [dvm](https://github.com/fnichol/dvm) on OS X)
13
13
  * A hostname of `docker` mapped to the IP of your container host (192.168.42.43 for dvm)
14
+ * At least 1Gb available to the docker VM. The base Erlang runtime seems to be a bit of a memory hog. (`export DOCKER_MEMORY=1024` for dvm)
14
15
 
15
16
  ## Installation
16
17
 
@@ -1,5 +1,7 @@
1
1
  require "expect"
2
2
  require "timeout"
3
+ require "open3"
4
+ require "json"
3
5
 
4
6
  module RiakTestServer
5
7
  class Error < StandardError; end
@@ -32,10 +34,16 @@ module RiakTestServer
32
34
  end
33
35
 
34
36
  def start
35
- if docker("ps -a") =~ /\b#{@container_name}\b/
36
- return unless @force_restart
37
- stop
38
- docker "rm #{@container_name}"
37
+ details = JSON.parse(docker("inspect #{@container_name}", allowed_exits: [0, 1]))
38
+ if details.size > 0
39
+ detail = details.first
40
+ running = (detail["State"] && detail["State"]["Running"])
41
+ if(@force_restart || !running)
42
+ stop
43
+ docker "rm #{@container_name}"
44
+ else
45
+ return
46
+ end
39
47
  end
40
48
 
41
49
  docker %W(
@@ -46,17 +54,17 @@ module RiakTestServer
46
54
  --publish=#{@http_port}:8098
47
55
  --publish=#{@pb_port}:8087
48
56
  #{@repository}:#{@tag}
49
- ).join(" "), 5
57
+ ).join(" "), timeout: 5
50
58
  end
51
59
 
52
60
  def stop
53
61
  @console_io.close if @console_io
54
- docker "stop #{@container_name}", 15
62
+ docker "stop #{@container_name}", timeout: 15
55
63
  end
56
64
 
57
65
  def setup
58
- unless docker("images", 5) =~ /#{repository}\s+#{tag}/
59
- docker "pull #{repository}:#{tag}", 60
66
+ unless docker("images", timeout: 5) =~ /#{repository}\s+#{tag}/
67
+ docker "pull #{repository}:#{tag}", timeout: 60
60
68
  end
61
69
  end
62
70
 
@@ -79,12 +87,20 @@ module RiakTestServer
79
87
 
80
88
  private
81
89
 
82
- def docker(command, timeout=1)
90
+ def docker(command, options={})
83
91
  full_command = "#{@docker_bin} #{command}"
92
+ timeout = (options[:timeout] || 1)
93
+ allowed_exits = (options[:allowed_exits] || [0])
84
94
  Timeout.timeout(timeout) do
85
- `#{full_command} 2>&1`.tap do |output|
86
- raise "#{full_command} failed: #{output}" unless $?.exitstatus == 0
95
+ stdout, stderr, status = Open3.capture3(full_command)
96
+ unless(allowed_exits.include?(status.exitstatus))
97
+ raise [
98
+ "#{full_command} exited with unexpected status #{status.exitstatus} (expected: #{allowed_exits.inspect})",
99
+ "STDOUT: #{stdout}",
100
+ "STDERR: #{stderr}"
101
+ ].join("\n")
87
102
  end
103
+ stdout
88
104
  end
89
105
  rescue Timeout::Error
90
106
  raise RiakTestServer::Error, "Timed out running `#{full_command}` after #{timeout} seconds; is your Docker host running?"
@@ -109,7 +125,7 @@ module RiakTestServer
109
125
  @console_io = IO.popen([@docker_bin, "attach", @container_name], "r+", err: :out).tap{|io| io.sync = true}
110
126
  @console_io.puts("ok.")
111
127
  unless @console_io.expect(PROMPT, 10)
112
- raise "Unable to get a prompt on the console"
128
+ raise "Unable to get a prompt on the console: @console_io.read"
113
129
  end
114
130
  end
115
131
 
@@ -1,3 +1,3 @@
1
1
  module RiakTestServer
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riak_test_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Talbott