]> Entropealabs - wampex_test_suite.git/commitdiff
update test suite
authorChristopher Coté <ccote@cohesionib.com>
Fri, 4 Dec 2020 04:21:06 +0000 (22:21 -0600)
committerChristopher Coté <ccote@cohesionib.com>
Fri, 4 Dec 2020 04:21:06 +0000 (22:21 -0600)
mix.exs
test/cluster_kv_test.exs
test/wampex_router_test.exs

diff --git a/mix.exs b/mix.exs
index 30cad0cf6988c55aebdec9c2b85f2aa881da3a9a..db09eba88b1bcb78f4c96930c1ffcdf805004db1 100644 (file)
--- 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
 
index 3335fba3954e133b581e8f99870540243c866722..05b9e937d7854887b3b30fc7a327bbb63cc04ff3 100644 (file)
@@ -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
index 45fbae72d7638252ffc4545d3ad7e0be40011b86..c4bfcaf8fd094c35e23ad375fd68f55ee4e0ed4a 100644 (file)
@@ -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