-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow online js_engine reconfiguration #5327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,9 @@ setup() -> | |||||
| test_util:start_couch(). | ||||||
|
|
||||||
| teardown(Ctx) -> | ||||||
| config:delete("quickjs", "memory_limit_bytes", _Persist = false), | ||||||
| Persist = false, | ||||||
| config:delete("quickjs", "memory_limit_bytes", Persist), | ||||||
| config:delete("couchdb", "js_engine", Persist), | ||||||
| test_util:stop_couch(Ctx). | ||||||
|
|
||||||
| quickjs_test_() -> | ||||||
|
|
@@ -30,7 +32,8 @@ quickjs_test_() -> | |||||
| ?TDEF_FE(t_get_mainjs_cmd), | ||||||
| ?TDEF_FE(t_get_coffee_cmd), | ||||||
| ?TDEF_FE(t_can_configure_memory_limit), | ||||||
| ?TDEF_FE(t_bad_memory_limit) | ||||||
| ?TDEF_FE(t_bad_memory_limit), | ||||||
| ?TDEF_FE(t_couch_jsengine_config_triggers_proc_server_reload) | ||||||
| ] | ||||||
| }. | ||||||
|
|
||||||
|
|
@@ -60,9 +63,58 @@ 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if you want to leave that in?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's a note that we're testing the case of a user running config:delete/3 and returning to the set of defaults. |
||||||
| 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; | ||||||
| not_found -> wait; | ||||||
| _ -> ok | ||||||
| end | ||||||
| end, | ||||||
| case test_util:wait(WaitFun, 4500) of | ||||||
| timeout -> error(timeout); | ||||||
| _ -> ok | ||||||
| end. | ||||||
|
|
||||||
| get_proc_manager_default_js() -> | ||||||
| case ets:lookup(couch_proc_manager_servers, "JAVASCRIPT") of | ||||||
| [{"JAVASCRIPT", Val}] -> Val; | ||||||
| _ -> not_found | ||||||
| end. | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe out of scope of this PR, but we might want to handle
handle_config_change("native_query_servers", _, _, _, _)in a similar way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do, it's just above in lines 283:285