grntest 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c4da22645c51bc7a2f74a60d727f04fc123f9f3
4
+ data.tar.gz: 9f01ad9f0c434f3922fda5b2db584861a9e79a19
5
+ SHA512:
6
+ metadata.gz: 1b740176e04d147d62c040eb1c98dc98619ffe033008aa44214e1475874b4308368d127d221784f4c8a52b85ec875755380c1f5a3837ed26de0dee34565f1ed8
7
+ data.tar.gz: 953b462900e9ecc68df27bf9bfd6996c1870450871a200774842aa9c9a5fa3df98bf9d28805893c6fb32c67a39bc6f201be763c071691ae02c2013e788ae419d
data/doc/text/news.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # News
2
2
 
3
+ ## 1.0.4: 2013-12-16
4
+
5
+ ### Improvements
6
+
7
+ * Supported `groogna-command-parser` gem.
8
+
3
9
  ## 1.0.3: 2013-08-12
4
10
 
5
11
  This is a minor improvment release.
data/grntest.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
45
45
 
46
46
  spec.add_runtime_dependency("json")
47
47
  spec.add_runtime_dependency("msgpack")
48
- spec.add_runtime_dependency("groonga-command")
48
+ spec.add_runtime_dependency("groonga-command-parser")
49
49
 
50
50
  spec.add_development_dependency("bundler")
51
51
  spec.add_development_dependency("rake")
@@ -19,7 +19,7 @@ require "pathname"
19
19
  require "fileutils"
20
20
  require "shellwords"
21
21
 
22
- require "groonga/command"
22
+ require "groonga/command/parser"
23
23
 
24
24
  require "grntest/error"
25
25
  require "grntest/execution-context"
@@ -54,10 +54,10 @@ module Grntest
54
54
  script_file.each_line do |line|
55
55
  begin
56
56
  parser << line
57
- rescue Error, Groonga::Command::ParseError
57
+ rescue Error, Groonga::Command::Parser::Error
58
58
  line_info = "#{script_path}:#{script_file.lineno}:#{line.chomp}"
59
59
  log_error("#{line_info}: #{$!.message}")
60
- if $!.is_a?(Groonga::Command::ParseError)
60
+ if $!.is_a?(Groonga::Command::Parser::Error)
61
61
  @context.abort
62
62
  else
63
63
  log_error("#{line_info}: #{$!.message}")
@@ -77,7 +77,17 @@ module Grntest
77
77
  parser.on_command do |command|
78
78
  execute_command(command)
79
79
  end
80
+ parser.on_load_value do |command, value|
81
+ command.values ||= []
82
+ command.values << value
83
+ end
80
84
  parser.on_load_complete do |command|
85
+ if command.columns
86
+ command[:columns] = command.columns.join(", ")
87
+ end
88
+ if command.values
89
+ command[:values] = JSON.generate(command.values)
90
+ end
81
91
  execute_command(command)
82
92
  end
83
93
  parser.on_comment do |comment|
@@ -240,12 +250,21 @@ module Grntest
240
250
  def execute_command(command)
241
251
  extract_command_info(command)
242
252
  log_input("#{command.original_source}\n")
243
- response = send_command(command)
244
- type = @output_type
245
- log_output(response)
246
- log_error(extract_important_messages(read_all_log))
253
+ begin
254
+ response = send_command(command)
255
+ rescue => error
256
+ log_error("# error: #{error.class}: #{error.message}")
257
+ error.backtrace.each do |line|
258
+ log_error("# error: #{line}")
259
+ end
260
+ @context.error
261
+ else
262
+ type = @output_type
263
+ log_output(response)
264
+ log_error(extract_important_messages(read_all_log))
247
265
 
248
- @context.error if error_response?(response, type)
266
+ @context.error if error_response?(response, type)
267
+ end
249
268
  end
250
269
 
251
270
  def read_all_log
@@ -26,24 +26,21 @@ module Grntest
26
26
  super(context)
27
27
  @host = host
28
28
  @port = port
29
+ @read_timeout = 3
29
30
  end
30
31
 
31
32
  def send_command(command)
32
- url = "http://#{@host}:#{@port}#{command.to_uri_format}"
33
- begin
34
- open(url) do |response|
35
- "#{response.read}\n"
36
- end
37
- rescue OpenURI::HTTPError
38
- message = "Failed to get response from groonga: #{$!}: <#{url}>"
39
- raise Error.new(message)
33
+ if command.name == "load"
34
+ send_load_command(command)
35
+ else
36
+ send_normal_command(command)
40
37
  end
41
38
  end
42
39
 
43
40
  def ensure_groonga_ready
44
41
  n_retried = 0
45
42
  begin
46
- send_command("status")
43
+ send_command(command("status"))
47
44
  rescue SystemCallError
48
45
  n_retried += 1
49
46
  sleep(0.1)
@@ -52,9 +49,54 @@ module Grntest
52
49
  end
53
50
  end
54
51
 
52
+ def shutdown
53
+ send_command(command("shutdown"))
54
+ end
55
+
55
56
  def create_sub_executor(context)
56
57
  self.class.new(@host, @port, context)
57
58
  end
59
+
60
+ private
61
+ def command(command_line)
62
+ Groonga::Command::Parser.parse(command_line)
63
+ end
64
+
65
+ MAX_URI_SIZE = 4096
66
+ def send_load_command(command)
67
+ if command.to_uri_format.size <= MAX_URI_SIZE
68
+ return send_normal_command(command)
69
+ end
70
+
71
+ values = command.arguments.delete(:values)
72
+ request = Net::HTTP::Post.new(command.to_uri_format)
73
+ request.content_type = "application/json; charset=UTF-8"
74
+ request.body = values
75
+ response = Net::HTTP.start(@host, @port) do |http|
76
+ http.read_timeout = @read_timeout
77
+ http.request(request)
78
+ end
79
+ normalize_response_data(response.body)
80
+ end
81
+
82
+ def send_normal_command(command)
83
+ url = "http://#{@host}:#{@port}#{command.to_uri_format}"
84
+ begin
85
+ open(url, :read_timeout => @read_timeout) do |response|
86
+ normalize_response_data(response.read)
87
+ end
88
+ rescue OpenURI::HTTPError
89
+ $!.io.read
90
+ end
91
+ end
92
+
93
+ def normalize_response_data(raw_response_data)
94
+ if raw_response_data.empty?
95
+ raw_response_data
96
+ else
97
+ "#{raw_response_data}\n"
98
+ end
99
+ end
58
100
  end
59
101
  end
60
102
  end
@@ -22,7 +22,7 @@ require "grntest/reporters/inplace-reporter"
22
22
  module Grntest
23
23
  module Reporters
24
24
  class << self
25
- def create_repoter(tester)
25
+ def create_reporter(tester)
26
26
  case tester.reporter
27
27
  when :mark
28
28
  MarkReporter.new(tester)
@@ -299,11 +299,25 @@ EOC
299
299
  end
300
300
  yield(executor)
301
301
  ensure
302
- executor.send_command("shutdown")
302
+ executor.shutdown
303
303
  wait_groonga_http_shutdown(pid_file_path)
304
304
  end
305
305
  ensure
306
- Process.waitpid(pid) if pid
306
+ ensure_process_finished(pid)
307
+ end
308
+ end
309
+
310
+ def ensure_process_finished(pid)
311
+ return if pid.nil?
312
+
313
+ n_retries = 0
314
+ loop do
315
+ finished_pid = Process.waitpid(pid, Process::WNOHANG)
316
+ break if finished_pid
317
+ n_retries += 1
318
+ break if n_retries > 10
319
+ Process.kill(:TERM, pid)
320
+ sleep(0.1)
307
321
  end
308
322
  end
309
323
 
@@ -135,7 +135,7 @@ module Grntest
135
135
  end
136
136
 
137
137
  def create_reporter
138
- Reporters.create_repoter(@tester)
138
+ Reporters.create_reporter(@tester)
139
139
  end
140
140
  end
141
141
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This program is free software: you can redistribute it and/or modify
4
4
  # it under the terms of the GNU General Public License as published by
@@ -14,5 +14,5 @@
14
14
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
15
 
16
16
  module Grntest
17
- VERSION = "1.0.3"
17
+ VERSION = "1.0.4"
18
18
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grntest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kouhei Sutou
@@ -10,150 +9,132 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-08-12 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: json
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: msgpack
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
- name: groonga-command
43
+ name: groonga-command-parser
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: bundler
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: rake
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: test-unit
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: test-unit-rr
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - '>='
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - '>='
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: packnga
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
- - - ! '>='
116
+ - - '>='
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
- - - ! '>='
123
+ - - '>='
141
124
  - !ruby/object:Gem::Version
142
125
  version: '0'
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: redcarpet
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
- - - ! '>='
130
+ - - '>='
149
131
  - !ruby/object:Gem::Version
150
132
  version: '0'
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
- - - ! '>='
137
+ - - '>='
157
138
  - !ruby/object:Gem::Version
158
139
  version: '0'
159
140
  description: ''
@@ -197,27 +178,26 @@ files:
197
178
  homepage: https://github.com/groonga/grntest
198
179
  licenses:
199
180
  - GPLv3 or later
181
+ metadata: {}
200
182
  post_install_message:
201
183
  rdoc_options: []
202
184
  require_paths:
203
185
  - lib
204
186
  required_ruby_version: !ruby/object:Gem::Requirement
205
- none: false
206
187
  requirements:
207
- - - ! '>='
188
+ - - '>='
208
189
  - !ruby/object:Gem::Version
209
190
  version: '0'
210
191
  required_rubygems_version: !ruby/object:Gem::Requirement
211
- none: false
212
192
  requirements:
213
- - - ! '>='
193
+ - - '>='
214
194
  - !ruby/object:Gem::Version
215
195
  version: '0'
216
196
  requirements: []
217
197
  rubyforge_project:
218
- rubygems_version: 1.8.23
198
+ rubygems_version: 2.0.14
219
199
  signing_key:
220
- specification_version: 3
200
+ specification_version: 4
221
201
  summary: Grntest is a testing framework for groonga. You can write a test for groonga
222
202
  by writing groonga commands and expected result.
223
203
  test_files: