1
votes

I'm going through the Elixir "Getting Started" tutorial, where the following code snippet is used:

test "removes buckets on exit", %{registry: registry} do
  KV.Registry.create(registry, "shopping")
  {:ok, bucket} = KV.Registry.lookup(registry, "shopping")
  Agent.stop(bucket)
  assert KV.Registry.lookup(registry, "shopping") == :error
end

Now, create/2 uses the cast operation whereas lookup uses call. So that means that an asynchronous call is executed and then immediately after that, a synchronous call which assumes the async action was performed successfully. Could timing issues result in the test failing when the code itself is correct, or is there some aspect of cast and call that I am missing?

1

1 Answers

3
votes

Since GenServer's process all messages sequentially, the lookup call would block until the previous cast completed so there should be no timing issues.