From b27d6d421d0f015a254733a1d77b74e82da7bd18 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christopher=20Cot=C3=A9?= Date: Thu, 3 Dec 2020 22:21:06 -0600 Subject: [PATCH] update test suite --- mix.exs | 3 +- test/cluster_kv_test.exs | 58 ++++++++++++++++++++++++++----------- test/wampex_router_test.exs | 33 ++++++++++----------- 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/mix.exs b/mix.exs index 30cad0c..db09eba 100644 --- a/mix.exs +++ b/mix.exs @@ -50,7 +50,8 @@ defmodule WampexTestSuite.MixProject do git: "https://gitlab.com/entropealabs/cluster_kv.git", tag: "dev", override: true}, {:wampex, git: "https://gitlab.com/entropealabs/wampex.git", tag: "dev", override: true}, {:wampex_client, git: "https://gitlab.com/entropealabs/wampex_client.git", tag: "dev"}, - {:wampex_router, git: "https://gitlab.com/entropealabs/wampex_router.git", tag: "dev"} + # git: "https://gitlab.com/entropealabs/wampex_router.git", tag: "dev"} + {:wampex_router, path: "../wampex_router"} ] end diff --git a/test/cluster_kv_test.exs b/test/cluster_kv_test.exs index 3335fba..05b9e93 100644 --- a/test/cluster_kv_test.exs +++ b/test/cluster_kv_test.exs @@ -46,29 +46,53 @@ defmodule ClusterKVTest do "" ) - ClusterKV.update(db, @keyspace, "test1:test", :cruel, fn {id, values}, value -> - {id, List.delete(values, value)} - end) + ClusterKV.update(db, @keyspace, "test1:test", :cruel, :remove) assert {"test1:test", [:world, :hello]} = ClusterKV.get(db, @keyspace, "test1:test") - end - test "update_if", %{db: db} do - assert :updated = - ClusterKV.update_if(db, @keyspace, "test.profile", :initial_value, &update_if/2) + ClusterKV.update(db, @keyspace, "test1:test", :hi, :replace) + + assert {"test1:test", [:hi]} = ClusterKV.get(db, @keyspace, "test1:test") + + ClusterKV.update(db, @keyspace, "test1:test", [:hello, :beautiful, :world], :replace_list) + + assert {"test1:test", [:hello, :beautiful, :world]} = + ClusterKV.get(db, @keyspace, "test1:test") + + ClusterKV.update(db, @keyspace, "test1:test", :beautiful, :last_30) + + assert {"test1:test", [:beautiful, :hello, :beautiful, :world]} = + ClusterKV.get(db, @keyspace, "test1:test") + + ClusterKV.update(db, @keyspace, "test1:test", :beautiful, :unique) + + assert {"test1:test", [:beautiful, :hello, :world]} = + ClusterKV.get(db, @keyspace, "test1:test") - assert :noop = - ClusterKV.update_if(db, @keyspace, "test.profile", :initial_value, &update_if/2) + ClusterKV.put(db, @keyspace, "test1:round-robin", 0) - assert :updated = ClusterKV.update_if(db, @keyspace, "test.profile", :new_value, &update_if/2) - assert :noop = ClusterKV.update_if(db, @keyspace, "test.profile", :new_value, &update_if/2) - assert :noop = ClusterKV.update_if(db, @keyspace, "test.profile", :new_value, &update_if/2) + assert {"test1:round-robin", [0]} = ClusterKV.get(db, @keyspace, "test1:round-robin") + + ClusterKV.update(db, @keyspace, "test1:round-robin", 3, :round_robin) + + assert {"test1:round-robin", [1]} = ClusterKV.get(db, @keyspace, "test1:round-robin") + + ClusterKV.update(db, @keyspace, "test1:round-robin", 3, :round_robin) + + assert {"test1:round-robin", [2]} = ClusterKV.get(db, @keyspace, "test1:round-robin") + + ClusterKV.update(db, @keyspace, "test1:round-robin", 3, :round_robin) + + assert {"test1:round-robin", [0]} = ClusterKV.get(db, @keyspace, "test1:round-robin") end - defp update_if({key, [old]}, val) do - case old == val do - true -> :noop - false -> {:update, {key, [val]}} - end + test "update_if", %{db: db} do + assert :updated = ClusterKV.update_if(db, @keyspace, "test.profile", :initial_value, :diff) + + assert :noop = ClusterKV.update_if(db, @keyspace, "test.profile", :initial_value, :diff) + + assert :updated = ClusterKV.update_if(db, @keyspace, "test.profile", :new_value, :diff) + assert :noop = ClusterKV.update_if(db, @keyspace, "test.profile", :new_value, :diff) + assert :noop = ClusterKV.update_if(db, @keyspace, "test.profile", :new_value, :diff) end end diff --git a/test/wampex_router_test.exs b/test/wampex_router_test.exs index 45fbae7..c4bfcaf 100644 --- a/test/wampex_router_test.exs +++ b/test/wampex_router_test.exs @@ -42,11 +42,19 @@ defmodule WampexRouterTest do id: Test ) + defmodule TestStruct do + defstruct [:test] + end + setup do start_supervised(@s) :ok end + test "struct is map" do + refute is_map(Client) + end + test "role not supported" do callee_name = TestCalleeAbortRegistration Client.start_link(name: callee_name, session: @session, reconnect: false) @@ -67,7 +75,7 @@ defmodule WampexRouterTest do name = TestCalleeRegistration Client.start_link(name: name, session: @session, reconnect: false) TestCallee.start_link(self(), name, @device) - assert_receive {:registered, id} + assert_receive {:registered, id}, 500 end @tag :abort @@ -100,7 +108,7 @@ defmodule WampexRouterTest do callee_name = TestErrorCalleeRespond Client.start_link(name: callee_name, session: @session, reconnect: false) TestCallee.start_link(self(), callee_name, @device) - assert_receive {_, _} + assert_receive {:registered, id} caller_name = TestErrorCaller Client.start_link(name: caller_name, session: @session, reconnect: false) @@ -120,7 +128,7 @@ defmodule WampexRouterTest do callee_name = TestCalleeRespond Client.start_link(name: callee_name, session: @session, reconnect: false) TestCallee.start_link(self(), callee_name, @device) - assert_receive {_, _} + assert_receive {:registered, id} caller_name = TestCaller Client.start_link(name: caller_name, session: @session, reconnect: false) @@ -150,6 +158,7 @@ defmodule WampexRouterTest do name = TestSubscriberDisconnectEvents Client.start_link(name: name, session: @session, reconnect: false) TestSubscriber.start_link(self(), name, "router.peer.disconnect") + assert_receive {:subscribed, id} Task.start(fn -> {:ok, pid} = @@ -159,7 +168,7 @@ defmodule WampexRouterTest do Process.exit(pid, :normal) end) - assert_receive %Event{details: %{"topic" => "router.peer.disconnect"}}, 2000 + assert_receive %Event{details: %{"topic" => "router.peer.disconnect"}}, 500 end @tag :client @@ -167,19 +176,9 @@ defmodule WampexRouterTest do name = TestSubscriberEvents Client.start_link(name: name, session: @session, reconnect: false) TestSubscriber.start_link(self(), name, "com.data.test.temp") - assert_receive {:subscribed, id} Client.start_link(name: TestPublisher, session: @session, reconnect: false) - Client.publish( - TestPublisher, - %Publish{ - topic: "no.subscribers", - arg_list: [12.5, 45.6, 87.5], - arg_kw: %{loc: "60645"} - } - ) - Client.publish( TestPublisher, %Publish{ @@ -189,8 +188,8 @@ defmodule WampexRouterTest do } ) - assert_receive %Event{details: %{"topic" => "com.data.test.temp"}}, 2000 - assert_receive %Event{details: %{"topic" => "com.data.test.temp"}}, 2000 - assert_receive %Event{details: %{"topic" => "com.data.test.temp"}}, 2000 + assert_receive %Event{details: %{"topic" => "com.data.test.temp"}} + assert_receive %Event{details: %{"topic" => "com.data.test.temp"}} + assert_receive %Event{details: %{"topic" => "com.data.test.temp"}} end end -- 2.45.3