Skip to content

Commit

Permalink
Added test to validate issue bitwalker#106
Browse files Browse the repository at this point in the history
- Added test for inspecting the node state after sync to make sure
  that clocks are still correct.
- Fix sync test which was not testing concurrent clocks
  • Loading branch information
tschmittni committed Nov 16, 2018
1 parent 6258e43 commit af4ec21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/swarm/tracker/tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ defmodule Swarm.Tracker do
%TrackerState{sync_node: sync_node} = state
)
when node(from) == sync_node do
info("received registry from #{sync_node}, merging #{inspect sync_clock}..")
info("received registry from #{sync_node}, merging..")
new_state = sync_registry(from, sync_clock, registry, state)
# let remote node know we've got the registry
GenStateMachine.cast(from, {:sync_ack, self(), sync_clock, get_registry_snapshot()})
Expand Down
13 changes: 11 additions & 2 deletions test/tracker_sync_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ defmodule Swarm.TrackerSyncTests do
[name: name, pid: pid, meta: meta, lclock: lclock, rclock: rclock]
end

test ":sync should set sync node and preserve node clock", %{pid: pid, meta: meta, rclock: rclock} do
{_, state_before} = :sys.get_state(Swarm.Tracker)
GenServer.cast(Swarm.Tracker, {:sync, self(), rclock})
{_, state_after} = :sys.get_state(Swarm.Tracker)

assert state_after.sync_node == :"primary@127.0.0.1"
assert state_after.sync_ref
assert state_after.clock == state_before.clock
end

test ":sync should add missing registration", %{pid: pid, meta: meta, rclock: rclock} do
name = random_name()

Expand Down Expand Up @@ -115,7 +125,6 @@ defmodule Swarm.TrackerSyncTests do
rclock: rclock
} do
Swarm.Tracker.add_meta(:new_local, "meta_local", pid)

rclock = Clock.event(rclock)

remote_registry = [
Expand All @@ -124,7 +133,7 @@ defmodule Swarm.TrackerSyncTests do
pid: pid,
ref: nil,
meta: %{new_remote: "remote_meta"},
clock: Clock.peek(rclock)
clock: Clock.peek(Clock.event(rclock))
)
]

Expand Down

0 comments on commit af4ec21

Please sign in to comment.