jiahuili430 commented on code in PR #5327: URL: https://github.com/apache/couchdb/pull/5327#discussion_r1821794892
########## 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: Works as expected. ```erl (node1@127.0.0.1)1> couch_server:get_js_engine(). <<"quickjs">> (node1@127.0.0.1)2> config:set("couchdb", "js_engine", "spidermonkey"). ok (node1@127.0.0.1)3> couch_server:get_js_engine(). <<"spidermonkey">> (node1@127.0.0.1)4> config:set("couchdb", "js_engine", "quickjs"). ok (node1@127.0.0.1)5> couch_server:get_js_engine(). <<"quickjs">> ``` Just curious what happens if I make a typo... Is that possible to avoid this error? ```bash (node1@127.0.0.1)6> config:set("couchdb", "js_engine", "spider_monkey"). ok *** ERROR: Shell process terminated! (^G to start new job) *** $ curl $DB curl: (7) Failed to connect to 127.0.0.1 port 15984 after 0 ms: Couldn't connect to server ``` -- 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