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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews