You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2014/06/03 17:54:49 UTC
[11/36] couchdb commit: updated refs/heads/1963-eunit to 85f2750
Port 041-uuid.t etap test suite to eunit
Config files are removed in favor of using couch_config API instead.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f33624f6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f33624f6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f33624f6
Branch: refs/heads/1963-eunit
Commit: f33624f6e8c229f977f250023b2bb88ca9067e95
Parents: e297472
Author: Alexander Shorin <kx...@apache.org>
Authored: Sat May 17 04:23:25 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Tue Jun 3 15:14:25 2014 +0400
----------------------------------------------------------------------
test/couchdb/Makefile.am | 1 +
test/couchdb/couch_uuids_tests.erl | 158 ++++++++++++++++++++++++++++++++
test/etap/041-uuid-gen-id.ini | 20 ----
test/etap/041-uuid-gen-seq.ini | 19 ----
test/etap/041-uuid-gen-utc.ini | 19 ----
test/etap/041-uuid-gen.t | 147 -----------------------------
test/etap/Makefile.am | 4 -
7 files changed, 159 insertions(+), 209 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index c67fe95..e7d13ff 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -22,6 +22,7 @@ eunit_files = \
couch_file_tests.erl \
couch_btree_tests.erl \
couch_doc_json_tests.erl \
+ couch_uuids_tests.erl \
couchdb_tests.hrl
EXTRA_DIST = \
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/couchdb/couch_uuids_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couch_uuids_tests.erl b/test/couchdb/couch_uuids_tests.erl
new file mode 100644
index 0000000..3e8b014
--- /dev/null
+++ b/test/couchdb/couch_uuids_tests.erl
@@ -0,0 +1,158 @@
+% 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(couch_uuids_tests).
+
+-include_lib("couchdb_tests.hrl").
+
+
+setup() ->
+ {ok, Pid} = couch_config:start_link(?CONFIG_CHAIN),
+ erlang:monitor(process, Pid),
+ couch_uuids:start(),
+ Pid.
+
+setup(Opts) ->
+ Pid = setup(),
+ lists:foreach(
+ fun({Option, Value}) ->
+ couch_config:set("uuids", Option, Value, false)
+ end, Opts),
+ Pid.
+
+teardown(Pid) ->
+ couch_uuids:stop(),
+ couch_config:stop(),
+ receive
+ {'DOWN', _, _, Pid, _} -> ok
+ after
+ 1000 -> throw({timeout_error, config_stop})
+ end.
+
+teardown(_, Pid) ->
+ teardown(Pid).
+
+
+default_test_() ->
+ {
+ "Default UUID algorithm",
+ {
+ setup,
+ fun setup/0, fun teardown/1,
+ fun should_be_unique/1
+ }
+ }.
+
+sequential_test_() ->
+ Opts = [{"algorithm", "sequential"}],
+ Cases = [
+ fun should_be_unique/2,
+ fun should_increment_monotonically/2,
+ fun should_rollover/2
+ ],
+ {
+ "UUID algorithm: sequential",
+ {
+ foreachx,
+ fun setup/1, fun teardown/2,
+ [{Opts, Fun} || Fun <- Cases]
+ }
+ }.
+
+utc_test_() ->
+ Opts = [{"algorithm", "utc_random"}],
+ Cases = [
+ fun should_be_unique/2,
+ fun should_increment_monotonically/2
+ ],
+ {
+ "UUID algorithm: utc_random",
+ {
+ foreachx,
+ fun setup/1, fun teardown/2,
+ [{Opts, Fun} || Fun <- Cases]
+ }
+ }.
+
+utc_id_suffix_test_() ->
+ Opts = [{"algorithm", "utc_id"}, {"utc_id_suffix", "bozo"}],
+ Cases = [
+ fun should_be_unique/2,
+ fun should_increment_monotonically/2,
+ fun should_preserve_suffix/2
+ ],
+ {
+ "UUID algorithm: utc_id",
+ {
+ foreachx,
+ fun setup/1, fun teardown/2,
+ [{Opts, Fun} || Fun <- Cases]
+ }
+ }.
+
+
+should_be_unique() ->
+ ?_assert(test_unique(10000, [couch_uuids:new()])).
+should_be_unique(_) ->
+ should_be_unique().
+should_be_unique(_, _) ->
+ should_be_unique().
+
+should_increment_monotonically(_, _) ->
+ ?_assert(couch_uuids:new() < couch_uuids:new()).
+
+should_rollover(_, _) ->
+ ?_test(begin
+ UUID = binary_to_list(couch_uuids:new()),
+ Prefix = element(1, lists:split(26, UUID)),
+ N = gen_until_pref_change(Prefix, 0),
+ ?assert(N >= 5000 andalso N =< 11000)
+ end).
+
+should_preserve_suffix(_, _) ->
+ ?_test(begin
+ UUID = binary_to_list(couch_uuids:new()),
+ Suffix = get_suffix(UUID),
+ ?assert(test_same_suffix(10000, Suffix))
+ end).
+
+
+test_unique(0, _) ->
+ true;
+test_unique(N, UUIDs) ->
+ UUID = couch_uuids:new(),
+ ?assertNot(lists:member(UUID, UUIDs)),
+ test_unique(N - 1, [UUID| UUIDs]).
+
+get_prefix(UUID) ->
+ element(1, lists:split(26, binary_to_list(UUID))).
+
+gen_until_pref_change(_, Count) when Count > 8251 ->
+ Count;
+gen_until_pref_change(Prefix, N) ->
+ case get_prefix(couch_uuids:new()) of
+ Prefix -> gen_until_pref_change(Prefix, N + 1);
+ _ -> N
+ end.
+
+get_suffix(UUID) when is_binary(UUID) ->
+ get_suffix(binary_to_list(UUID));
+get_suffix(UUID) ->
+ element(2, lists:split(14, UUID)).
+
+test_same_suffix(0, _) ->
+ true;
+test_same_suffix(N, Suffix) ->
+ case get_suffix(couch_uuids:new()) of
+ Suffix -> test_same_suffix(N - 1, Suffix);
+ _ -> false
+ end.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/etap/041-uuid-gen-id.ini
----------------------------------------------------------------------
diff --git a/test/etap/041-uuid-gen-id.ini b/test/etap/041-uuid-gen-id.ini
deleted file mode 100644
index 6886efd..0000000
--- a/test/etap/041-uuid-gen-id.ini
+++ /dev/null
@@ -1,20 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements. See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership. The ASF licenses this file
-; to you 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.
-
-[uuids]
-algorithm = utc_id
-utc_id_suffix = bozo
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/etap/041-uuid-gen-seq.ini
----------------------------------------------------------------------
diff --git a/test/etap/041-uuid-gen-seq.ini b/test/etap/041-uuid-gen-seq.ini
deleted file mode 100644
index 94cebc6..0000000
--- a/test/etap/041-uuid-gen-seq.ini
+++ /dev/null
@@ -1,19 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements. See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership. The ASF licenses this file
-; to you 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.
-
-[uuids]
-algorithm = sequential
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/etap/041-uuid-gen-utc.ini
----------------------------------------------------------------------
diff --git a/test/etap/041-uuid-gen-utc.ini b/test/etap/041-uuid-gen-utc.ini
deleted file mode 100644
index c2b8383..0000000
--- a/test/etap/041-uuid-gen-utc.ini
+++ /dev/null
@@ -1,19 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements. See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership. The ASF licenses this file
-; to you 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.
-
-[uuids]
-algorithm = utc_random
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/etap/041-uuid-gen.t
----------------------------------------------------------------------
diff --git a/test/etap/041-uuid-gen.t b/test/etap/041-uuid-gen.t
deleted file mode 100755
index 7234969..0000000
--- a/test/etap/041-uuid-gen.t
+++ /dev/null
@@ -1,147 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% 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.
-
-default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
-
-seq_alg_config() ->
- test_util:source_file("test/etap/041-uuid-gen-seq.ini").
-
-utc_alg_config() ->
- test_util:source_file("test/etap/041-uuid-gen-utc.ini").
-
-utc_id_alg_config() ->
- test_util:source_file("test/etap/041-uuid-gen-id.ini").
-
-% Run tests and wait for the gen_servers to shutdown
-run_test(IniFiles, Test) ->
- {ok, Pid} = couch_config:start_link(IniFiles),
- erlang:monitor(process, Pid),
- couch_uuids:start(),
- Test(),
- couch_uuids:stop(),
- couch_config:stop(),
- receive
- {'DOWN', _, _, Pid, _} -> ok;
- _Other -> etap:diag("OTHER: ~p~n", [_Other])
- after
- 1000 -> throw({timeout_error, config_stop})
- end.
-
-main(_) ->
- test_util:init_code_path(),
- application:start(crypto),
- etap:plan(9),
-
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
-
- TestUnique = fun() ->
- etap:is(
- test_unique(10000, couch_uuids:new()),
- true,
- "Can generate 10K unique IDs"
- )
- end,
- run_test([default_config()], TestUnique),
- run_test([default_config(), seq_alg_config()], TestUnique),
- run_test([default_config(), utc_alg_config()], TestUnique),
- run_test([default_config(), utc_id_alg_config()], TestUnique),
-
- TestMonotonic = fun () ->
- etap:is(
- couch_uuids:new() < couch_uuids:new(),
- true,
- "should produce monotonically increasing ids"
- )
- end,
- run_test([default_config(), seq_alg_config()], TestMonotonic),
- run_test([default_config(), utc_alg_config()], TestMonotonic),
- run_test([default_config(), utc_id_alg_config()], TestMonotonic),
-
- % Pretty sure that the average of a uniform distribution is the
- % midpoint of the range. Thus, to exceed a threshold, we need
- % approximately Total / (Range/2 + RangeMin) samples.
- %
- % In our case this works out to be 8194. (0xFFF000 / 0x7FF)
- % These tests just fudge the limits for a good generator at 25%
- % in either direction. Technically it should be possible to generate
- % bounds that will show if your random number generator is not
- % sufficiently random but I hated statistics in school.
- TestRollOver = fun() ->
- UUID = binary_to_list(couch_uuids:new()),
- Prefix = element(1, lists:split(26, UUID)),
- N = gen_until_pref_change(Prefix,0),
- etap:diag("N is: ~p~n",[N]),
- etap:is(
- N >= 5000 andalso N =< 11000,
- true,
- "should roll over every so often."
- )
- end,
- run_test([default_config(), seq_alg_config()], TestRollOver),
-
- TestSuffix = fun() ->
- UUID = binary_to_list(couch_uuids:new()),
- Suffix = get_suffix(UUID),
- etap:is(
- test_same_suffix(100, Suffix),
- true,
- "utc_id ids should have the same suffix."
- )
- end,
- run_test([default_config(), utc_id_alg_config()], TestSuffix).
-
-test_unique(0, _) ->
- true;
-test_unique(N, UUID) ->
- case couch_uuids:new() of
- UUID ->
- etap:diag("N: ~p~n", [N]),
- false;
- Else -> test_unique(N-1, Else)
- end.
-
-get_prefix(UUID) ->
- element(1, lists:split(26, binary_to_list(UUID))).
-
-gen_until_pref_change(_, Count) when Count > 8251 ->
- Count;
-gen_until_pref_change(Prefix, N) ->
- case get_prefix(couch_uuids:new()) of
- Prefix -> gen_until_pref_change(Prefix, N+1);
- _ -> N
- end.
-
-get_suffix(UUID) when is_binary(UUID)->
- get_suffix(binary_to_list(UUID));
-get_suffix(UUID) ->
- element(2, lists:split(14, UUID)).
-
-test_same_suffix(0, _) ->
- true;
-test_same_suffix(N, Suffix) ->
- case get_suffix(couch_uuids:new()) of
- Suffix -> test_same_suffix(N-1, Suffix);
- _ -> false
- end.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/f33624f6/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 64570a0..f45853a 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,10 +36,6 @@ fixture_files = \
fixtures/test.couch
tap_files = \
- 041-uuid-gen-id.ini \
- 041-uuid-gen-seq.ini \
- 041-uuid-gen-utc.ini \
- 041-uuid-gen.t \
042-work-queue.t \
043-find-in-binary.t \
050-stream.t \