Skip to content

Instantly share code, notes, and snippets.

@chewbranca
Created September 13, 2017 18:00
Show Gist options
  • Save chewbranca/4556422a7c82b476ff1590bc21c52844 to your computer and use it in GitHub Desktop.
Save chewbranca/4556422a7c82b476ff1590bc21c52844 to your computer and use it in GitHub Desktop.
diff --git a/src/couch.app.src b/src/couch.app.src
index cf3dc79..39e200a 100644
--- a/src/couch.app.src
+++ b/src/couch.app.src
@@ -47,6 +47,7 @@
couch_log,
couch_event,
ioq,
- couch_stats
+ couch_stats,
+ lethe
]}
]}.
diff --git a/src/couch_server.erl b/src/couch_server.erl
index 2c77e98..68c1537 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -235,7 +235,7 @@ terminate(Reason, Srv) ->
couch_log:error("couch_server terminating with ~p, state ~2048p",
[Reason,
Srv#server{lru = redacted}]),
- ets:foldl(fun(Db, _) ->
+ ets:foldl(fun(#entry{db=Db}, _) ->
couch_util:shutdown_sync(couch_db:get_pid(Db))
end, nil, couch_dbs),
ok.
diff --git a/src/test_engine_attachments.erl b/src/test_engine_attachments.erl
index a19322d..b0b3472 100644
--- a/src/test_engine_attachments.erl
+++ b/src/test_engine_attachments.erl
@@ -23,43 +23,47 @@ cet_write_attachment() ->
AttBin = crypto:rand_bytes(32768),
- [Att0] = test_engine_util:prep_atts(Engine, St1, [
- {<<"ohai.txt">>, AttBin}
- ]),
-
- {stream, Stream} = couch_att:fetch(data, Att0),
- ?assertEqual(true, Engine:is_active_stream(St1, Stream)),
-
- Actions = [{create, {<<"first">>, [], [Att0]}}],
- {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions),
- {ok, St3} = Engine:commit_data(St2),
- Engine:terminate(normal, St3),
-
- {ok, St4} = Engine:init(DbPath, []),
- [FDI] = Engine:open_docs(St4, [<<"first">>]),
-
- #rev_info{
- rev = {RevPos, PrevRevId},
- deleted = Deleted,
- body_sp = DocPtr
- } = test_engine_util:prev_rev(FDI),
-
- Doc0 = #doc{
- id = <<"foo">>,
- revs = {RevPos, [PrevRevId]},
- deleted = Deleted,
- body = DocPtr
- },
-
- Doc1 = Engine:read_doc_body(St4, Doc0),
- Atts1 = if not is_binary(Doc1#doc.atts) -> Doc1#doc.atts; true ->
- couch_compress:decompress(Doc1#doc.atts)
- end,
-
- StreamSrc = fun(Sp) -> Engine:open_read_stream(St4, Sp) end,
- [Att1] = [couch_att:from_disk_term(StreamSrc, T) || T <- Atts1],
- ReadBin = couch_att:to_binary(Att1),
- ?assertEqual(AttBin, ReadBin).
+ try
+ [Att0] = test_engine_util:prep_atts(Engine, St1, [
+ {<<"ohai.txt">>, AttBin}
+ ]),
+
+ {stream, Stream} = couch_att:fetch(data, Att0),
+ ?assertEqual(true, Engine:is_active_stream(St1, Stream)),
+
+ Actions = [{create, {<<"first">>, [], [Att0]}}],
+ {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions),
+ {ok, St3} = Engine:commit_data(St2),
+ Engine:terminate(normal, St3),
+
+ {ok, St4} = Engine:init(DbPath, []),
+ [FDI] = Engine:open_docs(St4, [<<"first">>]),
+
+ #rev_info{
+ rev = {RevPos, PrevRevId},
+ deleted = Deleted,
+ body_sp = DocPtr
+ } = test_engine_util:prev_rev(FDI),
+
+ Doc0 = #doc{
+ id = <<"foo">>,
+ revs = {RevPos, [PrevRevId]},
+ deleted = Deleted,
+ body = DocPtr
+ },
+
+ Doc1 = Engine:read_doc_body(St4, Doc0),
+ Atts1 = if not is_binary(Doc1#doc.atts) -> Doc1#doc.atts; true ->
+ couch_compress:decompress(Doc1#doc.atts)
+ end,
+
+ StreamSrc = fun(Sp) -> Engine:open_read_stream(St4, Sp) end,
+ [Att1] = [couch_att:from_disk_term(StreamSrc, T) || T <- Atts1],
+ ReadBin = couch_att:to_binary(Att1),
+ ?assertEqual(AttBin, ReadBin)
+ catch throw:not_supported ->
+ ok
+ end.
% N.B. This test may be overly specific for some theoretical
@@ -72,14 +76,18 @@ cet_inactive_stream() ->
AttBin = crypto:rand_bytes(32768),
- [Att0] = test_engine_util:prep_atts(Engine, St1, [
- {<<"ohai.txt">>, AttBin}
- ]),
+ try
+ [Att0] = test_engine_util:prep_atts(Engine, St1, [
+ {<<"ohai.txt">>, AttBin}
+ ]),
- {stream, Stream} = couch_att:fetch(data, Att0),
- ?assertEqual(true, Engine:is_active_stream(St1, Stream)),
+ {stream, Stream} = couch_att:fetch(data, Att0),
+ ?assertEqual(true, Engine:is_active_stream(St1, Stream)),
- Engine:terminate(normal, St1),
- {ok, St2} = Engine:init(DbPath, []),
+ Engine:terminate(normal, St1),
+ {ok, St2} = Engine:init(DbPath, []),
- ?assertEqual(false, Engine:is_active_stream(St2, Stream)).
+ ?assertEqual(false, Engine:is_active_stream(St2, Stream))
+ catch throw:not_supported ->
+ ok
+ end.
diff --git a/src/test_engine_compaction.erl b/src/test_engine_compaction.erl
index b178bae..619edd7 100644
--- a/src/test_engine_compaction.erl
+++ b/src/test_engine_compaction.erl
@@ -99,20 +99,24 @@ cet_compact_with_everything() ->
?assertEqual(PurgedIdRevs, lists:sort(Engine:get_last_purged(St6))),
- [Att0, Att1, Att2, Att3, Att4] = test_engine_util:prep_atts(Engine, St6, [
- {<<"ohai.txt">>, crypto:rand_bytes(2048)},
- {<<"stuff.py">>, crypto:rand_bytes(32768)},
- {<<"a.erl">>, crypto:rand_bytes(29)},
- {<<"a.hrl">>, crypto:rand_bytes(5000)},
- {<<"a.app">>, crypto:rand_bytes(400)}
- ]),
-
- Actions4 = [
- {create, {<<"small_att">>, [], [Att0]}},
- {create, {<<"large_att">>, [], [Att1]}},
- {create, {<<"multi_att">>, [], [Att2, Att3, Att4]}}
- ],
- {ok, St7} = test_engine_util:apply_actions(Engine, St6, Actions4),
+ {ok, St7} = try
+ [Att0, Att1, Att2, Att3, Att4] = test_engine_util:prep_atts(Engine, St6, [
+ {<<"ohai.txt">>, crypto:rand_bytes(2048)},
+ {<<"stuff.py">>, crypto:rand_bytes(32768)},
+ {<<"a.erl">>, crypto:rand_bytes(29)},
+ {<<"a.hrl">>, crypto:rand_bytes(5000)},
+ {<<"a.app">>, crypto:rand_bytes(400)}
+ ]),
+
+ Actions4 = [
+ {create, {<<"small_att">>, [], [Att0]}},
+ {create, {<<"large_att">>, [], [Att1]}},
+ {create, {<<"multi_att">>, [], [Att2, Att3, Att4]}}
+ ],
+ test_engine_util:apply_actions(Engine, St6, Actions4)
+ catch throw:not_supported ->
+ {ok, St6}
+ end,
{ok, St8} = Engine:commit_data(St7),
Db1 = test_engine_util:db_as_term(Engine, St8),
diff --git a/src/test_engine_util.erl b/src/test_engine_util.erl
index 33048d3..e920f13 100644
--- a/src/test_engine_util.erl
+++ b/src/test_engine_util.erl
@@ -42,12 +42,17 @@ create_tests(EngineApp, EngineModule) ->
Setup = fun() ->
Ctx = test_util:start_couch(),
config:set("log", "include_sasl", "false", false),
+ %%ok = application:start(EngineApp),
Ctx
end,
{
setup,
Setup,
- fun test_util:stop_couch/1,
+ %%fun test_util:stop_couch/1,
+ fun(Args) ->
+ %%application:stop(EngineApp),
+ test_util:stop_couch(Args)
+ end,
fun(_) -> Tests end
}.
@@ -357,6 +363,8 @@ prep_atts(Engine, St, [{FileName, Data} | Rest]) ->
exit(write_att(Stream, FileName, Data, Data))
end),
Att = receive
+ {'DOWN', Ref, _, _, {{nocatch, not_supported}, _}} ->
+ throw(not_supported);
{'DOWN', Ref, _, _, Resp} ->
Resp
after 5000 ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment