emacstheviking

emacstheviking

Apologies for this but…

can anybody point me where to go to get some help with commontest under rebar3 …I have no hair left. I have read the official documentation until it now just looks like colored pixels on my monitor I can absorb no more. I’ve tried google groups, the trap_exit site looks dead ( years since I looked). I don’t know where to turn :frowning:

I have never used ct before today… TBH either I am so dumb I don’t get it or it’s way too hard to get working, I’ve read the epgsql code again and again. I want a test suite to be able to drop and recreate a test database.

All I want is for my “application under test” to be able to “application:get_env/2” to work… it’s driving me freaking nuts. I had a bowel cancer op in March, I may well have to quite software engineering as this level of stress isn’t good for me I’m sure.

Thanks
Sean

Showing Posts 1 to 8

NobbZ

NobbZ

application:get_env/2 should work, can you perhaps share a minimal project that shows your problem?

PS: Remember that you need to make sure that the application is loaded before you can read its documentation. I’m not sure if CT did that by default.

emacstheviking

emacstheviking OP

Hi Nobbz,
I don’t think I can really…I have a “dbms” module that calls application:get_env/2 and the results is always undefined except when running normally from rebar shell.

I have been driven to the edge of the maelstrom by commontest today to be honest.

Ironically even running under rebar eunit is doing the same thing now…must have got out of bed the wrong way or something.

foo_test() ->
    Cfg = application:get_env(scofblog, dbms),
    ?assertNotMatch(Cfg, undefined).

running under rebar3 shell however it’s fine

1> application:get_env(scofblog, dbms).
{ok,[{server,"localhost"},
     {database,"scofblog"},
     {username,"sean"},
     {password,"???????"},
     {blogroot,"/home/sean/Documents/code/haskell/monadic-warrior-hakyll-site/posts"},
     {blogspec,"*.md"}]}

and he is my rebar.config file for good measure

{erl_opts, [debug_info]}.
{cover_enabled, true}.

{deps, [
    {epgsql,   {git, "https://github.com/epgsql/epgsql.git"},     {tag, "4.4.0"}},
    {cowboy,   {git, "https://github.com/ninenines/cowboy.git"},  {tag, "2.9.1"}},
    {jsone,    {git, "https://github.com/sile/jsone.git"},        {tag, "v0.3.3"}},
    {gen_smtp, {git, "https://github.com/gen-smtp/gen_smtp.git"}, {tag, "0.15.0"}}
]}.

{profiles,
 [
  {test,
   [
    {deps, [meck]}
   ]}
]}.


{shell, [
  % {config, "config/sys.config"},                                                             
    {apps, [scofblog]}
]}.

might as well throw in the failed suite as well

-module(dbms_SUITE).


-export([all/0,
         init_per_suite/1,
         init_per_testcase/2,
         end_per_suite/1,
         end_per_testcase/2
        ]).

-export([can_insert_row/1, can_insert_new_topic/1]).


-include("./src/scofblog_common.hrl").



all() -> [can_insert_new_topic, can_insert_row].


init_per_suite(_InitConfig) ->
    %% there MUST be a "rebar3" way of doing this, I read the epgsql
    %% test code for ages but really I just need to get this project
    %% finished for now!
    {ok, [{application, scofblog, Props}]}
        = file:consult("../../../../src/scofblog.app.src"),

    Env = ?prop(env, Props),
    Dbms = ?prop(dbms, Env),

    %% independant database connection
    {ok, C} =
        epgsql:connect(
          ?prop(server, Dbms),
          ?prop(username, Dbms),
          ?prop(password, Dbms),
          #{database=> "scofblog_test"}
         ),
    ct:pal("DBMS connected: ~w~n", [C]),
    [{conn, C}].


end_per_suite(Config) ->
    Conn = ?prop(conn, Config),
    epgsql:close(Conn),
    ct:pal("end_per_suite: DB Closeed OK~n",[]).


%% TEST init / end
init_per_testcase(Test, Config) ->
    ct:pal("init_per_testcase: for ~s~n", [Test]),
    C = ?prop(conn, Config),
    ct:pal("init_per_testcase: C: ~w~n", [C]),

    %T1 = epgsql:squery(C, "truncate comment cascade"),
    %T2 = epgsql:squery(C, "truncate author cascade"),
    %T3 = epgsql:squery(C, "truncate topic cascade"),

    %ct:pal("T1: ~w~n", [T1]),
    %ct:pal("T2: ~w~n", [T2]),
    %ct:pal("T3: ~w~n", [T3]),
    Config.

end_per_testcase(Test, _Config) ->
    ct:pal("end_per_testcase: ~s~n", [Test]).


can_insert_new_topic(_Cfg) ->
    {ok, TC} = test_connect(),
    epgsql:close(TC).


can_insert_row(Config) ->
    C = ?prop(conn, Config),
    ct:pal("TEST: can_insert_row: config: ~w~n", [C]),
    1 =:= 2.


test_connect() ->
    dbms:connect("scofblog_test").
rvirding

rvirding

Creator of Erlang

What do you see when start common test, and how do you start it? Do you see the output from your calls to ct:pall? Try adding an extra one to the start of init_per_suite/1 function. What is shown in the generated HTML files?

emacstheviking

emacstheviking OP

I do see the print-and-log output in the HTML files, that’s not a problem. I just can’t figure out why I can’t load my application:get_env() without so much trouble!

It’s been a few years since I used Erlang and EUnit but I don’t remember having this trouble before, stuff just worked like it said it should.

I’ve probably done something fundamentally borked but these things never transpire to reveal themselves until one has walked at least three lengths of the Nakatome building in bare feet…

emacstheviking

emacstheviking OP

Nobbz, I have realised that the application isn’t being loaded but I thought that at least running “rebar3 eunit” would do that for me but it doesn’t look that way.

I’ll be honest, I have found reading the manuals regarding EUnit and COmmonTest to be absolutely fruitless when trying to find a plain simple example of what I need: ensuring that my
src/scofblog.app.src is to hand at runtime.

That’s one thing I do remember, that the manuals are not the best sources of beginner level examples, I googled for about three hours on and off, found plenty of “solutions” but they are all years old and didn’t work anyway.

Still reading, gone back to EUnit manual and taking it one step at a time.
Again.
:expressionless:

emacstheviking

emacstheviking OP

Hello, sorry for the delay, went for a three hour walk to defuse my brain. Sore feet but clam head now.

I start with rebar3 ct or rebar3 eunit and no extra command line options.

Ultimately I lack the flying hours with the tools I guess. I have always loved Erlang since I first used it almost a decade ago and I do remember it being one tough cookie to crumble at times

:slight_smile:

rvirding

rvirding

Creator of Erlang

I have done most of my common test using the ct commands from the shell so I am not that into using rebar3. Can you check which applications are loaded and started. rebar3 shell does it for you automatically but I don’t know how the testing works.

emacstheviking

emacstheviking OP

I woke early with my head full of stuff… anyway, I think I have solved my problem by the simple addition of application:ensure_all_started, making my new working init_per_suite like so:

    application:ensure_all_started(scofblog),  
    {ok, Dbms} = application:get_env(scofblog, dbms),

    {ok, C} =
        epgsql:connect(
          ?prop(server, Dbms),
          ?prop(username, Dbms),
          ?prop(password, Dbms),
          #{database=> "scofblog_test"}
         ),
    [{conn, C}].

I found some code written by a work buddy from my current job, we use Erlang for talking to and from RabbitMQ and also to provide a common library that the Elixir applications use to “get on the bus”…lucky for me there was a -single- SUITE test that had that line in it, kind of obvious once you see it but not yesterday!

So, Robert, thanks for the nudges… a tad gutted I didn’t solve it myself but hell, at least I am moving forwards again, thanks again to everybody that helped a sometimes overly woud-up aging hacker… :expressionless:

I am still looking for a “solid” and “reliable” way to drop/recreate a test database, currently I create it manually and just truncate the tables to save some time…

Sean Charles.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews