nickva commented on code in PR #5327: URL: https://github.com/apache/couchdb/pull/5327#discussion_r1822714615
########## src/couch_quickjs/test/couch_quickjs_tests.erl: ########## @@ -60,9 +63,55 @@ t_bad_memory_limit(_) -> ?assertEqual(ExpectCmd, string:find(Cmd, ExpectCmd)), ?assertEqual(1, os_cmd(Cmd ++ " -V")). +t_couch_jsengine_config_triggers_proc_server_reload(_) -> + case couch_server:with_spidermonkey() of + false -> + % Spidermonkey is not in the build at all, skip the test + ok; + true -> + OldVal = get_proc_manager_default_js(), + % In the test, set the engine to whatever is not the default + Toggle = + case couch_server:get_js_engine() of + <<"quickjs">> -> "spidermonkey"; + <<"spidermonkey">> -> "quickjs" + end, + + config:set("couchdb", "js_engine", Toggle, false), + % couch_server:get_js_engine/0 should be visible immediately + ?assertEqual(list_to_binary(Toggle), couch_server:get_js_engine()), + + wait_until_proc_manager_updates(OldVal), + ?assertNotEqual(OldVal, get_proc_manager_default_js()), + NewVal = get_proc_manager_default_js(), + + % Toggle back to the original default (test config:delete/3) + config:delete("couchdb", "js_engine", false), + wait_until_proc_manager_updates(NewVal), + ?assertNotEqual(NewVal, get_proc_manager_default_js()), + % We should be back to the original default + ?assertEqual(OldVal, get_proc_manager_default_js()) + end. + os_cmd(Cmd) -> Opts = [stream, {line, 4096}, binary, exit_status, hide], Port = open_port({spawn, Cmd}, Opts), receive {Port, {exit_status, Status}} -> Status end. + +wait_until_proc_manager_updates(OldVal) -> + WaitFun = fun() -> + case get_proc_manager_default_js() of + OldVal -> wait; + _ -> ok + end + end, + case test_util:wait(WaitFun, 5000) of Review Comment: Currently it's somewhat intentional that it would crash on function clause on an invalid engine setting. But perhaps it's better to emit an error in the logs and then use the default? But I think that's for a separate PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org