You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/05/17 18:51:25 UTC

[couchdb] 03/04: Add more trace tests

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/rfc-001-revision-metadata-model
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e083075431c67958013060e163aa780ee6924a64
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue May 14 11:05:55 2019 -0500

    Add more trace tests
    
    These are useful when attempting to generate FoundationDB trace files
    for later analysis. They're broken out to be a simple of an operation as
    possible to avoid generate huge trace files of the larger more
    complicated tests.
---
 src/fabric/test/fabric2_trace_db_create_tests.erl  | 46 ++++++++++++++++++++
 src/fabric/test/fabric2_trace_db_delete_tests.erl  | 49 ++++++++++++++++++++++
 ...e_tests.erl => fabric2_trace_db_open_tests.erl} | 47 ++++-----------------
 src/fabric/test/fabric2_trace_doc_create_tests.erl | 29 ++++++++-----
 4 files changed, 122 insertions(+), 49 deletions(-)

diff --git a/src/fabric/test/fabric2_trace_db_create_tests.erl b/src/fabric/test/fabric2_trace_db_create_tests.erl
new file mode 100644
index 0000000..09cc863
--- /dev/null
+++ b/src/fabric/test/fabric2_trace_db_create_tests.erl
@@ -0,0 +1,46 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(fabric2_trace_db_create_tests).
+
+
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+
+trace_test_() ->
+    {
+        "Trace operation",
+        {
+            setup,
+            fun setup/0,
+            fun cleanup/1,
+            [
+                fun create_db/0
+            ]
+        }
+    }.
+
+
+setup() ->
+    put(erlfdb_trace, "starting fabric"),
+    test_util:start_couch([fabric]).
+
+
+cleanup(Ctx) ->
+    test_util:stop_couch(Ctx).
+
+
+create_db() ->
+    put(erlfdb_trace, <<"create db">>),
+    {ok, _Db} = fabric2_db:create(?tempdb(), [{user_ctx, ?ADMIN_USER}]).
diff --git a/src/fabric/test/fabric2_trace_db_delete_tests.erl b/src/fabric/test/fabric2_trace_db_delete_tests.erl
new file mode 100644
index 0000000..ddbb2c8
--- /dev/null
+++ b/src/fabric/test/fabric2_trace_db_delete_tests.erl
@@ -0,0 +1,49 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(fabric2_trace_db_delete_tests).
+
+
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+
+trace_test_() ->
+    {
+        "Trace operation",
+        {
+            setup,
+            fun setup/0,
+            fun cleanup/1,
+            {with, [
+                fun delete_db/1
+            ]}
+        }
+    }.
+
+
+setup() ->
+    put(erlfdb_trace, "starting fabric"),
+    Ctx = test_util:start_couch([fabric]),
+    {ok, Db} = fabric2_db:create(?tempdb(), [{user_ctx, ?ADMIN_USER}]),
+    {Db, Ctx}.
+
+
+cleanup({_Db, Ctx}) ->
+    test_util:stop_couch(Ctx).
+
+
+delete_db({Db, _}) ->
+    put(erlfdb_trace, <<"delete db">>),
+    fabric2_server:remove(fabric2_db:name(Db)),
+    ok = fabric2_db:delete(fabric2_db:name(Db), []).
diff --git a/src/fabric/test/fabric2_trace_doc_create_tests.erl b/src/fabric/test/fabric2_trace_db_open_tests.erl
similarity index 51%
copy from src/fabric/test/fabric2_trace_doc_create_tests.erl
copy to src/fabric/test/fabric2_trace_db_open_tests.erl
index 279533b..71e3301 100644
--- a/src/fabric/test/fabric2_trace_doc_create_tests.erl
+++ b/src/fabric/test/fabric2_trace_db_open_tests.erl
@@ -10,7 +10,7 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
--module(fabric2_trace_doc_create_tests).
+-module(fabric2_trace_db_open_tests).
 
 
 -include_lib("couch/include/couch_db.hrl").
@@ -18,23 +18,22 @@
 -include_lib("eunit/include/eunit.hrl").
 
 
-doc_crud_test_() ->
+trace_test_() ->
     {
-        "Test document CRUD operations",
+        "Trace operation",
         {
             setup,
             fun setup/0,
             fun cleanup/1,
             {with, [
-                fun create_new_doc/1,
-                fun create_two_docs/1,
-                fun create_50_docs/1
+                fun open_db/1
             ]}
         }
     }.
 
 
 setup() ->
+    put(erlfdb_trace, "starting fabric"),
     Ctx = test_util:start_couch([fabric]),
     {ok, Db} = fabric2_db:create(?tempdb(), [{user_ctx, ?ADMIN_USER}]),
     {Db, Ctx}.
@@ -45,35 +44,7 @@ cleanup({Db, Ctx}) ->
     test_util:stop_couch(Ctx).
 
 
-create_new_doc({Db, _}) ->
-    put(erlfdb_trace, true),
-    Doc = #doc{
-        id = fabric2_util:uuid(),
-        body = {[{<<"foo">>, <<"bar">>}]}
-    },
-    {ok, _} = fabric2_db:update_doc(Db, Doc).
-
-
-create_two_docs({Db, _}) ->
-    put(erlfdb_trace, true),
-    Doc1 = #doc{
-        id = fabric2_util:uuid(),
-        body = {[{<<"bam">>, <<"baz">>}]}
-    },
-    Doc2 = #doc{
-        id = fabric2_util:uuid(),
-        body = {[{<<"bang">>, <<"bargle">>}]}
-    },
-    {ok, _} = fabric2_db:update_docs(Db, [Doc1, Doc2]).
-
-
-create_50_docs({Db, _}) ->
-    put(erlfdb_trace, true),
-    Docs = lists:map(fun(Val) ->
-        #doc{
-            id = fabric2_util:uuid(),
-            body = {[{<<"value">>, Val}]}
-        }
-    end, lists:seq(1, 50)),
-    {ok, _} = fabric2_db:update_docs(Db, Docs).
-
+open_db({Db, _}) ->
+    put(erlfdb_trace, <<"open db">>),
+    fabric2_server:remove(fabric2_db:name(Db)),
+    {ok, _Db} = fabric2_db:open(fabric2_db:name(Db), [{user_ctx, ?ADMIN_USER}]).
diff --git a/src/fabric/test/fabric2_trace_doc_create_tests.erl b/src/fabric/test/fabric2_trace_doc_create_tests.erl
index 279533b..1e0b47c 100644
--- a/src/fabric/test/fabric2_trace_doc_create_tests.erl
+++ b/src/fabric/test/fabric2_trace_doc_create_tests.erl
@@ -46,7 +46,7 @@ cleanup({Db, Ctx}) ->
 
 
 create_new_doc({Db, _}) ->
-    put(erlfdb_trace, true),
+    put(erlfdb_trace, <<"one doc">>),
     Doc = #doc{
         id = fabric2_util:uuid(),
         body = {[{<<"foo">>, <<"bar">>}]}
@@ -55,7 +55,7 @@ create_new_doc({Db, _}) ->
 
 
 create_two_docs({Db, _}) ->
-    put(erlfdb_trace, true),
+    put(erlfdb_trace, <<"two docs">>),
     Doc1 = #doc{
         id = fabric2_util:uuid(),
         body = {[{<<"bam">>, <<"baz">>}]}
@@ -68,12 +68,19 @@ create_two_docs({Db, _}) ->
 
 
 create_50_docs({Db, _}) ->
-    put(erlfdb_trace, true),
-    Docs = lists:map(fun(Val) ->
-        #doc{
-            id = fabric2_util:uuid(),
-            body = {[{<<"value">>, Val}]}
-        }
-    end, lists:seq(1, 50)),
-    {ok, _} = fabric2_db:update_docs(Db, Docs).
-
+    lists:foreach(fun(_) ->
+        spawn_monitor(fun() ->
+            Name = io_lib:format("50 docs : ~w", [self()]),
+            put(erlfdb_trace, iolist_to_binary(Name)),
+            Docs = lists:map(fun(Val) ->
+                #doc{
+                    id = fabric2_util:uuid(),
+                    body = {[{<<"value">>, Val}]}
+                }
+            end, lists:seq(1, 50)),
+            {ok, _} = fabric2_db:update_docs(Db, Docs)
+        end)
+    end, lists:seq(1, 5)),
+    lists:foreach(fun(_) ->
+        receive {'DOWN', _, _, _, _} -> ok end
+    end, lists:seq(1, 5)).