You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2020/02/07 15:37:06 UTC

[couchdb] 03/03: Force OOM error

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c4aee4dc5b19cdcc55bb44e8863bc62403d635e6
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Feb 6 10:21:13 2020 -0600

    Force OOM error
    
    This changes the couchjs OOM test so that it will trigger more reliably
    on SpiderMonkey 60. It appears that newer SpiderMonkeys are better at
    conserving memory usage which takes this test longer to trigger.
---
 src/couch/test/eunit/couch_js_tests.erl | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/couch/test/eunit/couch_js_tests.erl b/src/couch/test/eunit/couch_js_tests.erl
index d3d92a2..cd6452c 100644
--- a/src/couch/test/eunit/couch_js_tests.erl
+++ b/src/couch/test/eunit/couch_js_tests.erl
@@ -15,9 +15,12 @@
 
 
 -define(FUNC, <<
+  "var state = [];\n"
   "function(doc) {\n"
   "  var val = \"0123456789ABCDEF\";\n"
-  "  while(true) {emit(val, val);}\n"
+  "  for(var i = 0; i < 165535; i++) {\n"
+  "    state.push([val, val]);\n"
+  "  }\n"
   "}\n"
 >>).
 
@@ -30,7 +33,7 @@ couch_js_test_() ->
             fun test_util:start_couch/0,
             fun test_util:stop_couch/1,
             [
-                fun should_exit_on_oom/0
+                {timeout, 60000, fun should_exit_on_oom/0}
             ]
         }
     }.
@@ -39,7 +42,16 @@ couch_js_test_() ->
 should_exit_on_oom() ->
     Proc = couch_query_servers:get_os_process(<<"javascript">>),
     true = couch_query_servers:proc_prompt(Proc, [<<"add_fun">>, ?FUNC]),
-    ?assertThrow(
-            {os_process_error, {exit_status, 1}},
-            couch_query_servers:proc_prompt(Proc, [<<"map_doc">>, <<"{}">>])
-        ).
+    trigger_oom(Proc).
+
+trigger_oom(Proc) ->
+    Status = try
+        couch_query_servers:proc_prompt(Proc, [<<"map_doc">>, <<"{}">>]),
+        continue
+    catch throw:{os_process_error, {exit_status, 1}} ->
+        done
+    end,
+    case Status of
+        continue -> trigger_oom(Proc);
+        done -> ok
+    end.