Kouhei Sutou
null+****@clear*****
Thu May 8 17:34:31 JST 2014
Kouhei Sutou 2014-05-08 17:34:31 +0900 (Thu, 08 May 2014) New Revision: 11a3b2338d4990158e935765b700e5cab2cbc10f https://github.com/groonga/groonga-query-log/commit/11a3b2338d4990158e935765b700e5cab2cbc10f Message: verify-server: support comparing errors Modified files: lib/groonga/query-log/response-comparer.rb lib/groonga/query-log/server-verifier.rb test/test-response-comparer.rb Modified: lib/groonga/query-log/response-comparer.rb (+25 -7) =================================================================== --- lib/groonga/query-log/response-comparer.rb 2014-05-08 17:33:53 +0900 (bc1b446) +++ lib/groonga/query-log/response-comparer.rb 2014-05-08 17:34:31 +0900 (887beea) @@ -26,23 +26,41 @@ module Groonga end def same? - case****@comma***** - when "select" - same_select_response? + if error_response?(@response1) or error_response?(@response2) + if error_response?(@response1) and error_response?(@response2) + same_error_response? + else + false + end else - same_response? + case****@comma***** + when "select" + same_select_response? + else + same_response? + end end end private + def error_response?(response) + response.is_a?(Client::Response::Error) + end + + def same_error_response? + return_code1 =****@respo*****[0] + return_code2 =****@respo*****[0] + return_code1 == return_code2 + end + def same_response? - @response1 == @response2 + @response1.body ==****@respo***** end def same_select_response? if random_sort? - records_result1 = @response1[0] || [] - records_result2 = @response2[0] || [] + records_result1 =****@respo*****[0] || [] + records_result2 =****@respo*****[0] || [] records_result1.size == records_result2.size and records_result1[0..1] == records_result2[0..1] else Modified: lib/groonga/query-log/server-verifier.rb (+1 -1) =================================================================== --- lib/groonga/query-log/server-verifier.rb 2014-05-08 17:33:53 +0900 (dfef48a) +++ lib/groonga/query-log/server-verifier.rb 2014-05-08 17:34:31 +0900 (a5b4481) @@ -111,7 +111,7 @@ module Groonga command["cache"] = "no" if****@optio*****_cache? response1 = groonga1_client.execute(command) response2 = groonga2_client.execute(command) - comparer = ResponseComparer.new(command, response1.body, response2.body) + comparer = ResponseComparer.new(command, response1, response2) unless comparer.same? @different_results.push([command, response1, response2]) end Modified: test/test-response-comparer.rb (+43 -2) =================================================================== --- test/test-response-comparer.rb 2014-05-08 17:33:53 +0900 (3a58898) +++ test/test-response-comparer.rb 2014-05-08 17:34:31 +0900 (33fcdf4) @@ -19,6 +19,8 @@ class ResponseComparerTest < Test::Unit::TestCase private def comparer(response1, response2) + response1 = normalize_response(response1) + response2 = normalize_response(response2) Groonga::QueryLog::ResponseComparer.new(@command, response1, response2) end @@ -26,6 +28,24 @@ class ResponseComparerTest < Test::Unit::TestCase comparer(response1, response2).same? end + def response(body) + header = [0, 0.0, 0.0] + response_class = Groonga::Client::Response.find(@command.name) + response_class.new(@command, header, body) + end + + def error_response(header) + Groonga::Client::Response::Error.new(@command, header, []) + end + + def normalize_response(response_or_body) + if response_or_body.is_a?(Groonga::Client::Response::Base) + response_or_body + else + response(response_or_body) + end + end + class SelectTest < self def setup @command = Groonga::Command::Select.new("select", {}) @@ -63,7 +83,7 @@ class ResponseComparerTest < Test::Unit::TestCase private def random_score?(scorer) @command["scorer"] = scorer - comparer([], []).send(:random_score?) + comparer([[[0]]], [[[0]]]).send(:random_score?) end end end @@ -73,7 +93,7 @@ class ResponseComparerTest < Test::Unit::TestCase private def score_sort?(sortby) @command["sortby"] = sortby - comparer([], []).send(:score_sort?) + comparer([[[0]]], [[[0]]]).send(:score_sort?) end class NoScoreTest < self @@ -119,5 +139,26 @@ class ResponseComparerTest < Test::Unit::TestCase end end end + + class ErrorTest < self + def test_with_location + response1_header = [ + -63, + 1.0, + 0.1, + "Syntax error! ()", + [ + ["yy_syntax_error", "ecmascript.lemon", 24], + ], + ] + response2_header = JSON.parse(response1_header.to_json) + response2_header[4][0][2] += 1 + assert_not_equal(response1_header, response2_header) + + response1 = error_response(response1_header) + response2 = error_response(response2_header) + assert_true(same?(response1, response2)) + end + end end end -------------- next part -------------- HTML����������������������������...Télécharger