[Groonga-commit] groonga/grntest [master] Support error log test

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 17日 (火) 23:04:52 JST


Kouhei Sutou	2012-07-17 23:04:52 +0900 (Tue, 17 Jul 2012)

  New Revision: 4f18cc73bdd78122b2b7ecec9e9cbeab4662924d
  https://github.com/groonga/grntest/commit/4f18cc73bdd78122b2b7ecec9e9cbeab4662924d

  Log:
    Support error log test

  Modified files:
    lib/groonga/tester.rb

  Modified: lib/groonga/tester.rb (+59 -19)
===================================================================
--- lib/groonga/tester.rb    2012-07-13 23:29:02 +0900 (f004cd8)
+++ lib/groonga/tester.rb    2012-07-17 23:04:52 +0900 (2f1c375)
@@ -417,6 +417,7 @@ EOC
           command_line << "--args"
         end
         command_line << groonga
+        command_line << "--log-path=#{context.log_path}"
         command_line
       end
 
@@ -485,6 +486,7 @@ EOC
             "--bind-address", host,
             "--port", port.to_s,
             "--protocol", @tester.protocol.to_s,
+            "--log-path", context.log_path,
             "-d",
             "-n", context.db_path,
           ]
@@ -637,6 +639,7 @@ EOF
           @groonga_suggest_create_dataset = "groonga-suggest-create-dataset"
           @n_nested = 0
           @result = []
+          @log = nil
         end
 
         def logging?
@@ -653,6 +656,14 @@ EOF
         def top_level?
           @n_nested == 1
         end
+
+        def log_path
+          File.join(@temporary_directory_path, "groonga.log")
+        end
+
+        def log
+          @log ||= File.open(log_path, "a+")
+        end
       end
 
       class Error < StandardError
@@ -707,7 +718,7 @@ EOF
         log_input(line)
         @pending_load_command << line
         if line == "]\n"
-          log_output(send_command(@pending_load_command))
+          execute_command(@pending_load_command)
           @pending_load_command = nil
           @loading = false
         end
@@ -735,7 +746,7 @@ EOF
           comment_content = $POSTMATCH
           execute_comment(comment_content)
         else
-          execute_command(line)
+          execute_command_line(line)
         end
       end
 
@@ -782,19 +793,19 @@ EOF
         executor.execute(script_path)
       end
 
-      def execute_command(line)
-        extract_command_info(line)
-        log_input(line)
+      def execute_command_line(command_line)
+        extract_command_info(command_line)
+        log_input(command_line)
         if @current_command == "load"
           @loading = true
-          @pending_load_command = line.dup
+          @pending_load_command = command_line.dup
         else
-          log_output(send_command(line))
+          execute_command(command_line)
         end
       end
 
-      def extract_command_info(line)
-        words = Shellwords.split(line)
+      def extract_command_info(command_line)
+        words = Shellwords.split(command_line)
         @current_command = words.shift
         if @current_command == "dump"
           @output_format = "groonga-command"
@@ -809,13 +820,50 @@ EOF
         end
       end
 
+      def execute_command(command)
+        log_output(send_command(command))
+        log_error(read_error_log)
+      end
+
+      def read_error_log
+        log = read_all_readable_content(context.log, :first_timeout => 0)
+        normalized_error_log = ""
+        log.each_line do |line|
+          timestamp, log_level, message = line.split(/\|\s*/, 3)
+          next unless error_log_level?(log_level)
+          next if backtrace_log_message?(message)
+          normalized_error_log << "\#|#{log_level}| #{message}"
+        end
+        normalized_error_log
+      end
+
+      def read_all_readable_content(output, options={})
+        content = ""
+        first_timeout = options[:first_timeout] || 1
+        timeout = first_timeout
+        while IO.select([output], [], [], timeout)
+          break if output.eof?
+          content << output.readpartial(65535)
+          timeout = 0
+        end
+        content
+      end
+
+      def error_log_level?(log_level)
+        ["E", "A", "C", "e"].include?(log_level)
+      end
+
+      def backtrace_log_message?(message)
+        message.start_with?("/")
+      end
+
       def log(tag, content, options={})
         return unles****@conte*****?
-        return if content.empty?
         log_force(tag, content, options)
       end
 
       def log_force(tag, content, options)
+        return if content.empty?
         @context.result << [tag, content, options]
       end
 
@@ -866,15 +914,7 @@ EOF
 
       private
       def read_output
-        output = ""
-        first_timeout = 1
-        timeout = first_timeout
-        while IO.select([@output], [], [], timeout)
-          break if****@outpu*****?
-          output << @output.readpartial(65535)
-          timeout = 0
-        end
-        output
+        read_all_readable_content(@output)
       end
     end
 
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
下载 



Groonga-commit メーリングリストの案内
Back to archive index