|
44 | 44 | -include("couch_db_int.hrl"). |
45 | 45 | -include("couch_bt_engine.hrl"). |
46 | 46 |
|
47 | | --record(test_context, {mocked = [], started = [], module, dir}). |
| 47 | +-record(test_context, {mocked = [], started = [], module}). |
48 | 48 |
|
49 | 49 | -define(DEFAULT_APPS, [inets, ibrowse, ssl, config, couch_epi, couch_event, couch]). |
50 | 50 |
|
@@ -81,61 +81,21 @@ start_couch() -> |
81 | 81 | start_couch(ExtraApps) -> |
82 | 82 | start_couch(?CONFIG_CHAIN, ExtraApps). |
83 | 83 |
|
84 | | -% This function starts CouchDB with optional extra apps in a dedicated |
85 | | -% directory under tmp/couchdb-tests/<uuid>/ — That is, all instances |
86 | | -% run isolated so that if more than one runs at a time, it does not |
87 | | -% interfere with any of the others. |
88 | | -% The sub-directories here are etc/ log/ and data/ for configuration |
89 | | -% logs and databases and view indexes respectively. |
90 | | -% The function copies the initial bespoke test-ini files to the new |
91 | | -% random directory and configures CouchDB to use those. |
92 | | -% The two pieces of state created here are the random dir in the file system and |
93 | | -% the process env var {config, ini_files} that is read by couch_config on |
94 | | -% startup. These need to be reset at the right points in time. |
95 | | -% the random dir is deleted and the env var reset when CouchDB is stopped. |
96 | | -% Note: there is currently a case where stop_couch/0 could be called and |
97 | | -% the file system cleanup can’t be run because we don’t get passed the test |
98 | | -% context with the random directory value. At the moment stop_couch/0 is not |
99 | | -% used anywhere, tho. Maybe we should remove it? |
100 | 84 | start_couch(IniFiles, ExtraApps) -> |
101 | | - RandomDir = filename:join([builddir(), "tmp", "couchdb-tests", couch_uuids:random()]), |
102 | | - RandomEtcDir = filename:join([RandomDir, "etc"]), |
103 | | - RandomDataDir = ?b2l(filename:join([RandomDir, "data"])), |
104 | | - RandomLogFile = ?b2l(filename:join([RandomDir, "log", "couch.log"])), |
105 | | - |
106 | | - ok = filelib:ensure_path(RandomDir), |
107 | | - ok = filelib:ensure_path(RandomEtcDir), |
108 | | - ok = filelib:ensure_path(RandomDataDir), |
109 | | - ok = filelib:ensure_dir(RandomLogFile), |
110 | | - |
111 | | - RandomIniFiles = lists:map( |
112 | | - fun(SourceFile) -> |
113 | | - TargetFileName = lists:last(filename:split(SourceFile)), |
114 | | - TargetFile = filename:join([RandomEtcDir, TargetFileName]), |
115 | | - {ok, _} = file:copy(SourceFile, TargetFile), |
116 | | - ?b2l(TargetFile) |
117 | | - end, |
118 | | - IniFiles |
119 | | - ), |
120 | 85 | load_applications_with_stats(), |
121 | | - ok = application:set_env(config, ini_files, RandomIniFiles), |
| 86 | + ok = application:set_env(config, ini_files, IniFiles), |
122 | 87 | Apps = start_applications(?DEFAULT_APPS ++ ExtraApps), |
123 | | - |
124 | | - ok = config:set("couchdb", "database_dir", RandomDataDir, false), |
125 | | - ok = config:set("couchdb", "view_index_dir", RandomDataDir, false), |
126 | | - ok = config:set("log", "file", RandomLogFile, false), |
127 | 88 | ok = config:delete("compactions", "_default", false), |
128 | | - #test_context{started = Apps, dir = RandomDir}. |
| 89 | + #test_context{started = Apps}. |
129 | 90 |
|
130 | 91 | stop_couch() -> |
131 | 92 | ok = stop_applications(?DEFAULT_APPS). |
132 | 93 |
|
133 | | -stop_couch(#test_context{started = Apps, dir = RandomDir}) -> |
134 | | - % deletion now happens in Makefile |
135 | | - % file:del_dir_r(RandomDir), |
| 94 | +stop_couch(#test_context{started = Apps}) -> |
136 | 95 | stop_applications(Apps); |
137 | 96 | stop_couch(_) -> |
138 | 97 | stop_couch(). |
| 98 | + |
139 | 99 | with_couch_server_restart(Fun) -> |
140 | 100 | Servers = couch_server:names(), |
141 | 101 | test_util:with_processes_restart(Servers, Fun). |
@@ -415,7 +375,7 @@ mock(couch_stats) -> |
415 | 375 | ok. |
416 | 376 |
|
417 | 377 | load_applications_with_stats() -> |
418 | | - Wildcard = filename:join([?BUILDDIR(), "src/*/priv/stats_descriptions.cfg"]), |
| 378 | + Wildcard = ?ABS_PATH("../*/priv/stats_descriptions.cfg"), |
419 | 379 | [application:load(stats_file_to_app(File)) || File <- filelib:wildcard(Wildcard)], |
420 | 380 | ok. |
421 | 381 |
|
|
0 commit comments