[erlang-questions] starting an app with an app.config file

Skip to first unread message

Roberto Ostinelli

unread,
Oct 14, 2012, 6:56:03 PM10/14/12
to Erlang
Dear list,

I have an application set up with the standard structure:

-- myproject
   rebar.config
   app.config
   |-- apps
       |-- myapp
           |--src
              ...
           |--test
              myapp_SUITE.erl
   |-- deps
       |-- dep1
       |-- dep2
   |-- ...

Please note app.config in there. Everything perfectly fine if I start myapp.

However, I'm trying to use Common Tests, and I start myapp in myapp_SUITE.erl during init:

init_per_suite(Config) ->
ok = application:start(myapp),
Config.

During startup, myapp tries to access config variables:

{ok, Port} = application:get_env(myapp, port),

This crashes in test, because application:get_env(myapp, port) returns undefined. This basically means that myapp does not load app.config.

How can I solve this?

Thank you,

r.

Roberto Ostinelli

unread,
Oct 14, 2012, 7:32:42 PM10/14/12
to Erlang
To extend: I can ensure that app.config is used:

  • when in development mode, by configuring it manually:
erl -pa apps/*/ebin -pa deps/*/ebin \
-boot start_sasl \
-config app \
-s myapp
  • when it is packaged as a release (i believe this can be managed by reltool)
But how can I set myapp to use it in common tests?

Andrew Gopienko

unread,
Oct 15, 2012, 1:40:24 AM10/15/12
to Roberto Ostinelli, erlang-q...@erlang.org
From my eunit tests

    SaslSpec = [{errlog_type, error}],
    case application:load({application,sasl,SaslSpec}) of
  {error,{already_loaded,_}} -> ok;
  ok ->
      ok = application:start(sasl),



2012/10/15 Roberto Ostinelli <rob...@widetag.com>
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


Roberto Ostinelli

unread,
Oct 15, 2012, 2:09:40 AM10/15/12
to Andrew Gopienko, erlang-q...@erlang.org, Roberto Ostinelli
What has this to do with my question?

My question is how can I use the same app.config file when I start an application from Common Tests.

Andrew Gopienko

unread,
Oct 15, 2012, 4:52:55 AM10/15/12
to Roberto Ostinelli, erlang-q...@erlang.org
Just read your config file and set env with application:load before application:start


2012/10/15 Roberto Ostinelli <rob...@widetag.com>

Roberto Ostinelli

unread,
Oct 15, 2012, 4:32:56 PM10/15/12
to Andrew Gopienko, erlang-q...@erlang.org
Oh I understand now.

Thank you Andrew, will try that.

r.

Roberto Ostinelli

unread,
Oct 20, 2012, 5:00:36 PM10/20/12
to Andrew Gopienko, erlang-q...@erlang.org
Hi,

this isn't working. From the docs:

load(AppDescr) -> ok | {error, Reason}
load(AppDescr, Distributed) -> ok | {error, Reason}

So application:load/2 actually is not reading from a config file.

Any other ideas?

r.

Jesse Gumm

unread,
Oct 20, 2012, 5:48:42 PM10/20/12
to Roberto Ostinelli, erlang-q...@erlang.org

Hi Roberto,

What about adding the app(s) to your appname.rel script in release/x.y.z and then using systools:make_script to generate the boot script.

That seems to work for me, anyway

-Jesse

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Motiejus Jakštys

unread,
Oct 20, 2012, 6:45:49 PM10/20/12
to Roberto Ostinelli, erlang-q...@erlang.org
On Sat, Oct 20, 2012 at 10:00 PM, Roberto Ostinelli <rob...@widetag.com> wrote:
> Hi,
>
> this isn't working. From the docs:
>
> load(AppDescr) -> ok | {error, Reason}
> load(AppDescr, Distributed) -> ok | {error, Reason}
>
> So application:load/2 actually is not reading from a config file.
>
> Any other ideas?

{ok, Config} = file:consult(File),
[application:set_env(myapp, K, V) | {K, V} <- Config].

Not tested.

Config might have to be [Config], you should try this out.

--
Motiejus Jakštys

Roberto Ostinelli

unread,
Oct 20, 2012, 8:00:50 PM10/20/12
to Motiejus Jakštys, erlang-q...@erlang.org
Hi Motiejus,

I'm doing something similar. It just feels weird. (:

r.

Phillip Toland

unread,
Oct 22, 2012, 2:36:49 PM10/22/12
to Roberto Ostinelli, erlang-q...@erlang.org
If you put an app.config file into the test directory, rebar will pick
it up. If you don't want to have two app.config files, then you can
use the ct_extra_params option in rebar.config. The value of that
option will be passed on the command line of the beam process that
runs the tests, so you could pass in something like "-config
app.config" and have it use the existing config file.

~p

> _______________________________________________
> erlang-questions mailing list
> erlang-q...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
~p

Reply all
Reply to author
Forward
0 new messages