From 5a9cdd3cc89507d4d74f8bded56ce5e037b3b56e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 23 Feb 2024 07:08:18 +0100 Subject: wip --- .../m8ball/test/dist_m8ball_SUITE.erl | 32 +++++++++++++++ .../test/dist_m8ball_SUITE_data/backup.config | 9 +++++ .../m8ball/test/dist_m8ball_SUITE_data/main.config | 9 +++++ learn-you-some-erlang/m8ball/test/m8ball.spec | 5 +++ learn-you-some-erlang/m8ball/test/m8ball_dist.spec | 20 ++++++++++ .../m8ball/test/m8ball_server_SUITE.erl | 45 ++++++++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE.erl create mode 100644 learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/backup.config create mode 100644 learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/main.config create mode 100644 learn-you-some-erlang/m8ball/test/m8ball.spec create mode 100644 learn-you-some-erlang/m8ball/test/m8ball_dist.spec create mode 100644 learn-you-some-erlang/m8ball/test/m8ball_server_SUITE.erl (limited to 'learn-you-some-erlang/m8ball/test') diff --git a/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE.erl b/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE.erl new file mode 100644 index 0000000..3afba6e --- /dev/null +++ b/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE.erl @@ -0,0 +1,32 @@ +-module(dist_m8ball_SUITE). +-include_lib("common_test/include/ct.hrl"). +-export([all/0, groups/0, init_per_group/2, end_per_group/2]). +-export([can_contact/1]). + +all() -> [{group, main}, {group, backup}]. + +groups() -> [{main, + [], + [can_contact]}, + {backup, + [], + [can_contact]}]. + +init_per_group(main, Config) -> + application:start(crypto), + application:start(m8ball), + Config; +init_per_group(backup, Config) -> + application:start(crypto), + application:start(m8ball), + Config. + +end_per_group(main, _Config) -> + %application:stop(m8ball), + ok; +end_per_group(backup, _Config) -> + %application:stop(m8ball), + ok. + +can_contact(_Config) -> + <<_/binary>> = m8ball:ask(<<"Some Question">>). diff --git a/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/backup.config b/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/backup.config new file mode 100644 index 0000000..7fbe260 --- /dev/null +++ b/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/backup.config @@ -0,0 +1,9 @@ +[{kernel, + [{distributed, [{m8ball, + 5000, + ['a@li101-172.members.linode.com', 'b@li101-172.members.linode.com']}]}, + {sync_nodes_mandatory, ['a@li101-172.members.linode.com']}, + {sync_nodes_timeout, 5000} + ] + } +]. diff --git a/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/main.config b/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/main.config new file mode 100644 index 0000000..bcac447 --- /dev/null +++ b/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/main.config @@ -0,0 +1,9 @@ +[{kernel, + [{distributed, [{m8ball, + 5000, + ['a@li101-172.members.linode.com', 'b@li101-172.members.linode.com']}]}, + {sync_nodes_mandatory, ['b@li101-172.members.linode.com']}, + {sync_nodes_timeout, 5000} + ] + } +]. diff --git a/learn-you-some-erlang/m8ball/test/m8ball.spec b/learn-you-some-erlang/m8ball/test/m8ball.spec new file mode 100644 index 0000000..51d9cf3 --- /dev/null +++ b/learn-you-some-erlang/m8ball/test/m8ball.spec @@ -0,0 +1,5 @@ +{include, "../include/"}. +{alias, root, "/home/ferd/code/learn-you-some-erlang/m8ball/test"}. +{logdir, "/home/ferd/code/learn-you-some-erlang/m8ball/logs"}. + +{suites, root, all}. diff --git a/learn-you-some-erlang/m8ball/test/m8ball_dist.spec b/learn-you-some-erlang/m8ball/test/m8ball_dist.spec new file mode 100644 index 0000000..c49a6ca --- /dev/null +++ b/learn-you-some-erlang/m8ball/test/m8ball_dist.spec @@ -0,0 +1,20 @@ +{node, master, 'ct@li101-172.members.linode.com'}. +{node, a, 'a@li101-172.members.linode.com'}. +{node, b, 'b@li101-172.members.linode.com'}. + +{init, a, [{node_start, [{monitor_master, true}, + {boot_timeout, 10000}, + {erl_flags, "-pa /home/ferd/code/learn-you-some-erlang/m8ball/ebin/ " + "-config /home/ferd/code/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/main.config"}]}]}. +{init, b, [{node_start, [{monitor_master, true}, + {boot_timeout, 10000}, + {erl_flags, "-pa /home/ferd/code/learn-you-some-erlang/m8ball/ebin/ " + "-config /home/ferd/code/learn-you-some-erlang/m8ball/test/dist_m8ball_SUITE_data/backup.config"}]}]}. + +{include, "../include/"}. +{alias, root, "/home/ferd/code/learn-you-some-erlang/m8ball/test"}. +{logdir, "/home/ferd/code/learn-you-some-erlang/m8ball/logs"}. +{logdir, master, "/home/ferd/code/learn-you-some-erlang/m8ball/logs"}. + +{groups, a, root, dist_m8ball_SUITE, main}. +{groups, b, root, dist_m8ball_SUITE, backup}. diff --git a/learn-you-some-erlang/m8ball/test/m8ball_server_SUITE.erl b/learn-you-some-erlang/m8ball/test/m8ball_server_SUITE.erl new file mode 100644 index 0000000..6bc4156 --- /dev/null +++ b/learn-you-some-erlang/m8ball/test/m8ball_server_SUITE.erl @@ -0,0 +1,45 @@ +-module(m8ball_server_SUITE). +-include_lib("common_test/include/ct.hrl"). +-export([all/0, init_per_testcase/2, end_per_testcase/2]). +-export([random_answer/1, binary_answer/1, determined_answers/1, + reload_answers/1]). + +all() -> [random_answer, binary_answer, determined_answers, + reload_answers]. + +init_per_testcase(_Test, Config) -> + Answers = [<<"Outlook not so good">>, + <<"I don't think so">>, + <<"Yes, definitely">>, + <<"STOP SHAKING ME">>], + application:set_env(m8ball, answers, list_to_tuple(Answers)), + m8ball_server:start_link(), + [{answers, Answers} | Config]. + +end_per_testcase(_Test, _Config) -> + m8ball_server:stop(). + +%% The answer should come from the config +random_answer(_Config) -> + Answers1 = [m8ball_server:ask("Dummy question") || _ <- lists:seq(1,15)], + Answers2 = [m8ball_server:ask("Dummy question") || _ <- lists:seq(1,15)], + true = 1 < length(sets:to_list(sets:from_list(Answers1))), + true = Answers1 =/= Answers2. + +binary_answer(_Config) -> + Answers = [m8ball_server:ask("Dummy question") || _ <- lists:seq(1,15)], + L = length(Answers), + L = length(lists:filter(fun erlang:is_binary/1, Answers)). + +determined_answers(Config) -> + Answers = ?config(answers, Config), + Res = [m8ball_server:ask("Dummy question") || _ <- lists:seq(1,15)], + true = lists:all(fun(X) -> lists:member(X, Answers) end, Res). + +reload_answers(_Config) -> + Ref = make_ref(), + application:set_env(m8ball, answers, {Ref}), + [Ref,Ref,Ref] = [m8ball_server:ask("Question") || _ <- lists:seq(1,3)]. + + +%% NOTE: do distributed testing in m8ball_SUITE or something -- cgit v1.2.3