[Groonga-commit] ranguba/chupa-text-http-server at f437cf6 [master] Add a test for timeout

Back to archive index
Sutou Kouhei null+****@clear*****
Fri Jun 14 11:35:50 JST 2019


Sutou Kouhei	2019-06-14 11:35:50 +0900 (Fri, 14 Jun 2019)

  Revision: f437cf6359e82c45daf82cc2cf697a88e920613f
  https://github.com/ranguba/chupa-text-http-server/commit/f437cf6359e82c45daf82cc2cf697a88e920613f

  Message:
    Add a test for timeout

  Added files:
    test/fixtures/files/hello.unknown
  Modified files:
    Gemfile
    test/controllers/extractions_controller_test.rb

  Modified: Gemfile (+1 -1)
===================================================================
--- Gemfile    2019-06-13 18:40:00 +0900 (9f44f1f)
+++ Gemfile    2019-06-14 11:35:50 +0900 (a4268ca)
@@ -62,7 +62,7 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
 gem 'bootstrap'
 gem 'jquery-rails'
 
-gem 'chupa-text', '>= 1.2.8'#, path: '../chupa-text'
+gem 'chupa-text', '>= 1.3.0'#, path: '../chupa-text'
 local_gemfile = "#{__dir__}/Gemfile.local"
 if File.exist?(local_gemfile)
   eval(File.read(local_gemfile), binding, local_gemfile, 1)

  Modified: test/controllers/extractions_controller_test.rb (+41 -0)
===================================================================
--- test/controllers/extractions_controller_test.rb    2019-06-13 18:40:00 +0900 (57f5421)
+++ test/controllers/extractions_controller_test.rb    2019-06-14 11:35:50 +0900 (9a54c2e)
@@ -426,5 +426,46 @@ class ExtractionsControllerTest < ActionDispatch::IntegrationTest
                      extract("hello.pptx"))
       end
     end
+
+    sub_test_case "options" do
+      test "timeout" do
+        class UnknownDecomposer < ChupaText::Decomposer
+          def target?(data)
+            data.extension == "unknown"
+          end
+
+          def decompose(data)
+            extracted = ChupaText::Data.new
+            extracted.mime_type = "text/plain"
+            extracted.body = data.body.gsub(/<.+?>/, "")
+            timeout_value = ChupaText::TimeoutValue.new("[decomposer]",
+                                                        data.timeout)
+            timeout = timeout_value.raw
+            sleep(timeout * 2) if timeout
+            yield(extracted)
+          end
+        end
+
+        Extraction.extractor.add_decomposer(UnknownDecomposer.new({}))
+        path = "hello.unknown"
+        timeout = "0.001"
+        post(extraction_url(format: "json"),
+             params: {
+               data: fixture_file_upload(file_fixture(path)),
+               timeout: timeout,
+             })
+        assert_equal("application/json", response.content_type,
+                     response.body)
+        top_dir = File.expand_path("../../", __dir__)
+        assert_equal({
+                       "data" => [
+                         "Timeout error: " +
+                         "<file://#{top_dir}/#{path}>(): " +
+                         "<#{timeout}>",
+                       ],
+                     },
+                     JSON.parse(response.body))
+      end
+    end
   end
 end

  Added: test/fixtures/files/hello.unknown (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/fixtures/files/hello.unknown    2019-06-14 11:35:50 +0900 (e965047)
@@ -0,0 +1 @@
+Hello
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190614/7f10261e/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index