Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Gaining independence #4

Closed
wants to merge 14 commits into from
Closed

Gaining independence #4

wants to merge 14 commits into from

Conversation

elbrujohalcon
Copy link

This PR includes a couple of tiny fixes that basically ensure that you can run and test the app by just cloning the repo and executing things like make app, make shell and/or make test

- fixing the CONFIG_FIXTURESDIR path
- ensuring that required dirs are created before creating a file in them
- adding a default_eunit.ini file
- making sure some required files are there before starting the tests
@@ -0,0 +1,27 @@
export BUILDDIR ?= /Users/elbrujohalcon/Projects/inaka/couchdb-config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header should be applied for Makefiles as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default path also should be changed for something that will works for everyone.

@kxepal
Copy link
Member

kxepal commented Jun 18, 2015

The problem of this PR that it cannot solve dependency issues. If your main goal of these changes was to be able to run the test suite without external dependencies, then the test suite should be changed (actually, improved) in order to run unit tests, not integrational as it does now.

In this case there would be no need in couch_eunit copy-paste, all external deps will be mocked and couchdb-config would be tested isolated from other CouchDB parts.

@elbrujohalcon
Copy link
Author

@kxepal my goal was to be able to run the app without CouchDB.
Initially, I only need it as a sample app, but it may eventually be useful for other non-couchdb users.

@kxepal
Copy link
Member

kxepal commented Jun 18, 2015

@elbrujohalcon I see. This is a good goal and I also want that (: In fact, for some apps that could not be so easy.

@kxepal
Copy link
Member

kxepal commented Jun 18, 2015

@elbrujohalcon Thanks! But something went wrong:

$ make test
rebar skip_deps=true compile
==> couchdb-config (compile)
mkdir -p tmp/etc;
cp test/fixtures/default_eunit.ini tmp/etc/default_eunit.ini;
touch tmp/etc/local_eunit.ini;
touch tmp/etc/eunit.ini;
rebar eunit
==> couchdb-config (eunit)
ERROR: eunit failed while processing /home/kxepal/projects/asf/couchdb/couchdb-config: {'EXIT',{{badmatch,{ok,[99,112,58,32,119,97,114,110,105,110,103,58,32,115,111,
                        117,114,99,101,32,102,105,108,101,32,226,128,152,116,
                        101,115,116,47,99,111,110,102,105,103,95,116,101,115,
                        116,115,46,101,114,108,226,128,153,32,115,112,101,99,
                        105,102,105,101,100,32,109,111,114,101,32,116,104,97,
                        110,32,111,110,99,101,10]}},
         [{rebar_file_utils,cp_r,2,
                            [{file,"src/rebar_file_utils.erl"},{line,68}]},
          {rebar_erlc_compiler,test_compile,3,
                               [{file,"src/rebar_erlc_compiler.erl"},
                                {line,179}]},
          {rebar_eunit,eunit,2,[{file,"src/rebar_eunit.erl"},{line,88}]},
          {rebar_core,run_modules,4,[{file,"src/rebar_core.erl"},{line,490}]},
          {rebar_core,execute,6,[{file,"src/rebar_core.erl"},{line,415}]},
          {rebar_core,maybe_execute,8,
                      [{file,"src/rebar_core.erl"},{line,299}]},
          {rebar_core,process_dir1,7,[{file,"src/rebar_core.erl"},{line,258}]},
          {rebar_core,process_commands,2,
                      [{file,"src/rebar_core.erl"},{line,90}]}]}}
Makefile:28: recipe for target 'test' failed
make: *** [test] Error 1

Any ideas?

@elbrujohalcon
Copy link
Author

It's basically saying

cp: warning: source file �test/config_tests.erl� specified more than once

I'm not sure why, but I pushed one commit more with a change that may or may not help. It's a very long shot, but just in case… Can you try again?

clean: app
${REBAR} clean

test: app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use make check to run the tests for other subprojects. Could you add it here? Alias is fine.

@kxepal
Copy link
Member

kxepal commented Jun 18, 2015

@elbrujohalcon Last commit fixed that problem, thanks!

@kxepal
Copy link
Member

kxepal commented Jun 18, 2015

LGFM. @rnewson @janl what would you say?

@elbrujohalcon
Copy link
Author

make check … I like it :) make test was always an itchy thing (because of the test folder) and erlang.mk's make tests was… well… not my favourite way to solve it. I like your approach 👍

{noreply, State};
handle_info(Info, State) ->
couch_log:error("config:handle_info Info: ~p~n", [Info]),
couch_log:notice("config:handle_info Info: ~p~n", [Info]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be switched back to the original levels.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, fixing that right away

@chewbranca
Copy link
Contributor

I like where you're going with this @elbrujohalcon!

One thing to be aware of, is that we run the test suite for this application as part of a parent application in http://github.com/apache/couchdb, so the duplication of couch_eunit.hrl is problematic. Although it looks like ?BUILDDIR and ?CONFIG_CHAIN are the only things used there. I think it would be good to see if we skip using those entirely and not need to include couch_eunit.hrl.

@elbrujohalcon
Copy link
Author

Let's try that out, @chewbranca … wait for my next commit

@elbrujohalcon
Copy link
Author

This whole thing lead me to detect a missing dep in couch-lager as well. Check PR apache/couchdb-lager#1, guys

@elbrujohalcon
Copy link
Author

⚠️ Don't merge this PR without merging apache/couchdb-lager#1 first ⚠️
I previously added couch_log as a dependency but I wasn't actually using it (i.e. I wasn't starting the application), otherwise I would've noticed the missing goldrush dependency first.

@chewbranca
Copy link
Contributor

Thanks @elbrujohalcon! If I use apache/couchdb-lager#1 all the tests pass.

I'm +1 although I wonder if there's a way we can get rid of ?BUILDDIR and ?CONFIG_CHAIN entirely, or perhaps expose them as config_eunit.hrl in this application and let the other couchdb-* applications include the macros from here.

Also, given this is one of the first applications that's being modified to run outside of CouchDB itself, it would be good to get some feedback from @rnewson and @janl.

@kxepal
Copy link
Member

kxepal commented Jun 18, 2015

\o/ Thanks @chewbranca for review!

@@ -0,0 +1,18 @@
relx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use relx or erlang.mk or Mnesia, where is this list coming from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the generic .gitignore we use at @inaka for all erlang projects, I can trim it down.

@rnewson
Copy link
Member

rnewson commented Jun 19, 2015

The whole point of having separate repos was to ensure they'd be able to evolve independently, so I'm definitely for the idea. I think the addition of a Makefile and changes to rebar.config are a problem, though, for the two different situations where we build this. I'd also like to discover why we used error_logger here rather than couch_log. It doesn't appear to be to break a cyclical dependency, so I'm inferring it was done that way so that couchdb-config does not have a dependency on couch_log at all. We shouldn't revert that choice lightly.

I hate to say it, but I'd like to hold off merging this until the 2.0 release. We can then think about how the build and test system can work in a more modular fashion.

Unless someone here is going to verify that this change works both ways satisfactorily?

@kxepal
Copy link
Member

kxepal commented Jun 19, 2015

@rnewson you're right, there are problems with running test suite from couchdb repo with this (and lager) PR applied:

==> couchdb (setup_eunit)
ERROR: One or more files already exist on disk and were not generated:
    * "tmp/etc/default_eunit.ini"
    * "tmp/etc/local_eunit.ini"
    * "tmp/etc/eunit.ini"
    * "tmp/etc/vm.args"
To force overwriting, specify -f/--force/force=1 on the command line.
==> b64url (eunit)
======================== EUnit ========================
module 'b64url'
  module 'b64url_tests'
    b64url_tests: table_test...ok
    b64url_tests: encode_binary_test...[1.030 s] ok
    b64url_tests: encode_iolist_test...[1.017 s] ok
    b64url_tests: decode_binary_test...[1.074 s] ok
    b64url_tests: decode_iolist_test...[1.240 s] ok
    b64url_tests: decode_binary_error_test...[1.052 s] ok
    b64url_tests: decode_bad_length_test...[0.780 s] ok
    [done in 6.211 s]
  [done in 6.211 s]
=======================================================
  All 7 tests passed.
==> cassim (eunit)
======================== EUnit ========================
module 'cassim_security'
module 'cassim'
module 'cassim_metadata_cache'
module 'cassim_app'
cassim_metadata_cache_test: security_meta_id_test (module 'cassim_metadata_cache_test')...[0.085 s] ok
module 'cassim_sup'
=======================================================
  Test passed.
==> couch_log (eunit)
======================== EUnit ========================
module 'couch_log'
  There were no tests to run.
==> config (eunit)
======================== EUnit ========================
module 'config_app'
module 'config_util'
module 'config_listener'
module 'config'
  module 'config_tests'
    CouchDB config tests
      Config get tests
        config_tests:236: should_load_all_configs...13:14:33.656 [info] Application lager started on node nonode@nohost
13:14:33.656 [info] Application couch_log started on node nonode@nohost
13:14:33.657 [info] Application config started on node nonode@nohost
ok
13:14:33.661 [info] Application config exited with reason: stopped
13:14:33.669 [info] Application config started on node nonode@nohost
        config_tests:239: should_locate_daemons_section...ok
13:14:33.672 [info] Application config exited with reason: stopped
13:14:33.679 [info] Application config started on node nonode@nohost
        config_tests:242: should_locate_mrview_handler...ok
13:14:33.682 [info] Application config exited with reason: stopped
13:14:33.689 [info] Application config started on node nonode@nohost
        config_tests:246: should_return_undefined_atom_on_missed_section...ok
13:14:33.692 [info] Application config exited with reason: stopped
13:14:33.699 [info] Application config started on node nonode@nohost
        config_tests:250: should_return_undefined_atom_on_missed_option...ok
13:14:33.702 [info] Application config exited with reason: stopped
        13:14:33.709 [info] Application config started on node nonode@nohost
config_tests:254: should_return_custom_default_value_on_missed_option...ok
13:14:33.712 [info] Application config exited with reason: stopped
13:14:33.720 [info] Application config started on node nonode@nohost
        config_tests:258: should_only_return_default_on_missed_option...ok
13:14:33.723 [info] Application config exited with reason: stopped
13:14:33.730 [info] Application config started on node nonode@nohost
        config_tests:262: should_fail_to_get_binary_value...ok
13:14:33.733 [info] Application config exited with reason: stopped
13:14:33.740 [info] Application config started on node nonode@nohost
        config_tests:269: should_return_any_supported_default (for type(undefined))...ok
        config_tests:269: should_return_any_supported_default (for type("list"))...ok
        config_tests:269: should_return_any_supported_default (for type(true))...ok
        config_tests:269: should_return_any_supported_default (for type(false))...ok
        config_tests:269: should_return_any_supported_default (for type(0.1))...ok
        config_tests:269: should_return_any_supported_default (for type(1))...ok
        13:14:33.758 [info] Application config exited with reason: stopped
[done in 0.321 s]
      Config set tests
13:14:33.766 [info] Application config started on node nonode@nohost
        config_tests:273: should_update_option...13:14:33.790 [notice] config: [log] level set to severe for reason nil
[0.024 s] ok
13:14:33.793 [info] Application config exited with reason: stopped
13:14:33.800 [info] Application config started on node nonode@nohost
13:14:33.801 [notice] config: [new_section] bizzle set to bang for reason nil
        config_tests:280: should_create_new_section...ok
13:14:33.804 [info] Application config exited with reason: stopped
        config_tests:288: should_fail_to_set_binary_value...ok
        [done in 0.057 s]
      Config deletion tests
13:14:33.823 [notice] config: [log] level deleted for reason nil
        config_tests:292: should_return_undefined_atom_after_option_deletion...ok
        13:14:33.833 [notice] config: [zoo] boo deleted for reason nil
config_tests:299: should_be_ok_on_deleting_unknown_options...ok
        [done in 0.021 s]
      Configs overide tests
        config_tests:302: should_ensure_in_defaults...*failed*
in function config_tests:'-should_ensure_in_defaults/2-fun-1-'/1 (test/config_tests.erl, line 306)
in call from config_tests:'-should_ensure_in_defaults/2-fun-3-'/0 (test/config_tests.erl, line 305)
**error:{assertEqual_failed,[{module,config_tests},
                     {line,306},
                     {expression,"config : get ( \"httpd\" , \"port\" )"},
                     {expected,"0"},
                     {value,"5986"}]}


        undefined
        *** context setup failed ***
**in function config_tests:setup/1 (test/config_tests.erl, line 66)
**error:{badmatch,
    {error,
        {config,
            {{shutdown,
                 {failed_to_start_child,config,
                     {bad_return_value,
                         {startup_error,<<"Couldn't fin"...>>}}}},
             {config_app,start,[normal,[]]}}}}}


      undefined
      *** context setup failed ***
**in function config_tests:setup/1 (test/config_tests.erl, line 66)
**error:{badmatch,
    {error,
        {config,
            {{shutdown,
                 {failed_to_start_child,config,
                     {bad_return_value,
                         {startup_error,<<"Couldn't fin"...>>}}}},
             {config_app,start,[normal,[]]}}}}}


    undefined
    *** context setup failed ***
**in function config_tests:setup/1 (test/config_tests.erl, line 66)
**error:{badmatch,
    {error,
        {config,
            {{shutdown,
                 {failed_to_start_child,config,
                     {bad_return_value,
                         {startup_error,<<"Couldn't fin"...>>}}}},
             {config_app,start,[normal,[]]}}}}}


  [done in 0.095 s]
Config persistent changes
  config_tests:331: should_write_changes...*failed*
in function config_tests:'-should_write_changes/2-fun-0-'/1 (test/config_tests.erl, line 333)
in call from config_tests:'-should_write_changes/2-fun-5-'/0 (test/config_tests.erl, line 332)
**error:{assertEqual_failed,[{module,config_tests},
                     {line,333},
                     {expression,"config : get ( \"httpd\" , \"port\" )"},
                     {expected,"0"},
                     {value,"5986"}]}


13:14:33.852 [error] Couldn't find server configuration file /home/kxepal/projects/asf/couchdb/couchdb/test/fixtures/config_tests_1.ini.
  config_tests:345: should_ensure_that_default_wasnt_modified...*failed*
in function config_tests:'-should_ensure_that_default_wasnt_modified/2-fun-0-'/1 (test/config_tests.erl, line 347)
in call from config_tests:'-should_ensure_that_default_wasnt_modified/2-fun-2-'/0 (test/config_tests.erl, line 346)
**error:{assertEqual_failed,[{module,config_tests},
                     {line,347},
                     {expression,"config : get ( \"httpd\" , \"port\" )"},
                     {expected,"0"},
                     {value,"5986"}]}


  config_tests:353: should_ensure_that_written_to_last_config_in_chain...*failed*
in function config_tests:'-should_ensure_that_written_to_last_config_in_chain/2-fun-0-'/1 (test/config_tests.erl, line 355)
in call from config_tests:'-should_ensure_that_written_to_last_config_in_chain/2-fun-2-'/0 (test/config_tests.erl, line 354)
**error:{assertEqual_failed,[{module,config_tests},
                     {line,355},
                     {expression,"config : get ( \"httpd\" , \"port\" )"},
                     {expected,"8080"},
                     {value,undefined}]}


  [done in 0.034 s]
Test config with no files
  config_tests:361: should_ensure_that_no_ini_files_loaded...ok
  config_tests:364: should_create_non_persistent_option...ok
  config_tests:371: should_create_persistent_option...ok
  [done in 0.013 s]
Test config_listener behaviour
  config_tests:378: should_handle_value_change...[0.001 s] ok
13:14:33.858 [error] Couldn't find server configuration file /home/kxepal/projects/asf/couchdb/couchdb/test/fixtures/config_tests_2.ini.
13:14:33.931 [error] Couldn't find server configuration file /home/kxepal/projects/asf/couchdb/couchdb/test/fixtures/config_tests_1.ini.
13:14:33.971 [notice] config: [httpd] port set to 80 for reason nil
13:14:33.975 [notice] config: [httpd] bind_address set to 127.0.0.1 for reason nil
13:14:33.988 [notice] config: [httpd] port set to 80 for reason nil
13:14:34.992 [notice] config_listener(config_tests) stopped with reason: shutdown
13:14:34.993 [warning] lager_error_logger_h dropped 3 messages in the last second that exceeded the limit of 50 messages/sec
13:14:34.993 [info] Application config exited with reason: stopped
13:14:35.004 [info] Application config started on node nonode@nohost
  config_tests:383: should_pass_correct_state_to_handle_config_change...13:14:35.004 [notice] config: [httpd] port set to 80 for reason nil
13:14:35.005 [notice] config: [update_state] foo set to any for reason nil
ok
13:14:36.009 [notice] config_listener(config_tests) stopped with reason: shutdown
13:14:36.010 [info] Application config exited with reason: stopped
13:14:36.028 [info] Application config started on node nonode@nohost
  13:14:36.029 [notice] config: [httpd] port set to 80 for reason nil
config_tests:390: should_pass_correct_state_to_handle_config_terminate...13:14:36.029 [notice] config: [update_state] foo set to any for reason nil
13:14:36.029 [notice] config: [remove_handler] any set to any for reason nil
13:14:36.029 [info] config_listener(config_tests) stopped with reason: shutdown
[0.001 s] ok
13:14:36.034 [info] Application config exited with reason: stopped
13:14:36.049 [info] Application config started on node nonode@nohost
  config_tests:407: should_pass_subscriber_pid_to_handle_config_terminate...13:14:36.049 [notice] config: [remove_handler] any set to any for reason nil
13:14:36.049 [info] config_listener(config_tests) stopped with reason: shutdown
[0.001 s] ok
  config_tests:416: should_not_call_handle_config_after_related_process_death...ok
  config_tests:425: should_remove_handler_when_requested...ok
  [done in 2.176 s]
[done in 2.718 s]
[done in 2.718 s]
[done in 2.719 s]
13:14:36.052 [error] Supervisor config_sup had child config started with config:start_link(["/home/kxepal/projects/asf/couchdb/couchdb/tmp/etc/default_eunit.ini","/home/kxepal/projects/as...",...]) at <0.411.0> exit with reason shutdown in context shutdown_error
13:14:36.053 [info] Application config exited with reason: stopped
13:14:36.135 [info] Application config started on node nonode@nohost
13:14:36.135 [notice] config: [remove_handler] any set to any for reason nil
13:14:36.135 [info] config_listener(config_tests) stopped with reason: shutdown
13:14:36.135 [notice] config: [httpd] port set to 80 for reason nil
13:14:36.139 [info] Application config exited with reason: stopped
13:14:36.150 [info] Application config started on node nonode@nohost
13:14:36.150 [notice] config: [remove_handler] any set to any for reason nil
13:14:36.150 [info] config_listener(config_tests) stopped with reason: shutdown
13:14:36.153 [error] Supervisor config_sup had child config started with config:start_link(["/home/kxepal/projects/asf/couchdb/couchdb/tmp/etc/default_eunit.ini","/home/kxepal/projects/as...",...]) at <0.431.0> exit with reason shutdown in context shutdown_error
13:14:36.154 [info] Application config exited with reason: stopped
module 'config_writer'
module 'config_sup'
=======================================================
  Failed: 4.  Skipped: 0.  Passed: 28.
One or more tests were cancelled.

=INFO REPORT==== 19-Jun-2015::13:14:36 ===
    application: lager
    exited: stopped
    type: temporary
ERROR: One or more eunit tests failed.

=INFO REPORT==== 19-Jun-2015::13:14:36 ===
    application: goldrush
    exited: killed
    type: temporary
ERROR: eunit failed while processing /home/kxepal/projects/asf/couchdb/couchdb/src/config: rebar_abort
Makefile:69: recipe for target 'eunit' failed
make: *** [eunit] Error 1

While tests are passed when runs only from couchdb-config repository.

@janl
Copy link
Member

janl commented Jun 20, 2015

I do like @rnewson’s take. 2.0 is a bit of a moving target when it comes to building and testing for a little while longer. I love where this work is going and it is going to make CouchDB a lot better. Are we cool leaving this to merge just after 2.x.x was branched?

@elbrujohalcon
Copy link
Author

I have no objections to that, @janl :)

@davisp
Copy link
Member

davisp commented Aug 10, 2016

Neat, just saw this and agree it would be nice. Definitely agree that we'll want to hold off until after 2.0.

As for the logging things, I didn't see the error_logger version but that's fine for us in CouchDB land as couch_log installs an error_logger event handler and forwards to the same place. We just need to make sure that whatever error report we use can be formatted by couch_log which is more than fine.

I'm pretty sure if its got a rebar.config and looks like an erlang app that make won't be run when we build downstream so that seems fine as well.

@elbrujohalcon
Copy link
Author

This PR is a bit old, I think I'll just close it :trollface:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants