Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb/pull/253#discussion_r14908936
  
    --- Diff: test/couchdb/couch_work_queue_tests.erl ---
    @@ -0,0 +1,393 @@
    +% 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_work_queue_tests).
    +
    +-include("couch_eunit.hrl").
    +
    +-define(TIMEOUT, 100).
    +
    +
    +setup(Opts) ->
    +    {ok, Q} = couch_work_queue:new(Opts),
    +    Producer = spawn_producer(Q),
    +    Consumer = spawn_consumer(Q),
    +    {Q, Producer, Consumer}.
    +
    +setup_max_items() ->
    +    setup([{max_items, 3}]).
    +
    +setup_max_size() ->
    +    setup([{max_size, 160}]).
    +
    +setup_max_items_and_size() ->
    +    setup([{max_size, 160}, {max_items, 3}]).
    +
    +setup_multi_workers() ->
    +    {Q, Producer, Consumer1} = setup([{max_size, 160},
    +                                      {max_items, 3},
    +                                      {multi_workers, true}]),
    +    Consumer2 = spawn_consumer(Q),
    +    Consumer3 = spawn_consumer(Q),
    +    {Q, Producer, [Consumer1, Consumer2, Consumer3]}.
    +
    +teardown({Q, Producer, Consumers}) when is_list(Consumers) ->
    +    % consume all to unblock and let producer/consumer stop without timeout
    +    [consume(Consumer, all) || Consumer <- Consumers],
    +
    +    ok = close_queue(Q),
    +    ok = stop(Producer, "producer"),
    +    R = [stop(Consumer, "consumer") || Consumer <- Consumers],
    +    R = [ok || _ <- Consumers],
    +    ok;
    +teardown({Q, Producer, Consumer}) ->
    +    teardown({Q, Producer, [Consumer]}).
    +
    +
    +single_consumer_test_() ->
    +    {
    +        "Single producer and consumer",
    +        [
    +            {
    +                "Queue with 3 max items",
    +                {
    +                    foreach,
    +                    fun setup_max_items/0, fun teardown/1,
    +                    single_consumer_max_item_count() ++ common_cases()
    +                }
    +            },
    +            {
    +                "Queue with max size of 160 bytes",
    +                {
    +                    foreach,
    +                    fun setup_max_size/0, fun teardown/1,
    +                    single_consumer_max_size() ++ common_cases()
    +                }
    +            },
    +            {
    +                "Queue with max size of 160 bytes and 3 max items",
    +                {
    +                    foreach,
    +                    fun setup_max_items_and_size/0, fun teardown/1,
    +                    single_consumer_max_items_and_size() ++ common_cases()
    +                }
    +            }
    +        ]
    +    }.
    +
    +multiple_consumers_test_() ->
    +    {
    +        "Single producer and multiple consumers",
    +        [
    +            {
    +                "Queue with max size of 160 bytes and 3 max items",
    +                {
    +                    foreach,
    +                    fun setup_multi_workers/0, fun teardown/1,
    +                    common_cases() ++ multiple_consumers()
    --- End diff --
    
    Could you be more verbose about? I don't see there any pattern and how it 
can be used in other files.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to