Skip to content

Commit

Permalink
Merge branch 'foo' into further-memory-improvements
Browse files Browse the repository at this point in the history
upgrade tests
  • Loading branch information
benwilson512 committed Apr 3, 2021
2 parents 6e6ed49 + 4ea707b commit 77a91d3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ missing_rules.rb
.DS_Store
/priv/plts/*.plt
/priv/plts/*.plt.hash
.vscode/
38 changes: 2 additions & 36 deletions test/absinthe/execution/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,6 @@ defmodule Absinthe.Execution.SubscriptionTest do

import ExUnit.CaptureLog

defmodule PubSub do
@behaviour Absinthe.Subscription.Pubsub

def start_link() do
Registry.start_link(keys: :unique, name: __MODULE__)
end

def node_name() do
node()
end

def subscribe(topic) do
Registry.register(__MODULE__, topic, [])
:ok
end

def publish_subscription(topic, data) do
message = %{
topic: topic,
event: "subscription:data",
result: data
}

Registry.dispatch(__MODULE__, topic, fn entries ->
for {pid, _} <- entries, do: send(pid, {:broadcast, message})
end)
end

def publish_mutation(_proxy_topic, _mutation_result, _subscribed_fields) do
# this pubsub is local and doesn't support clusters
:ok
end
end

defmodule Schema do
use Absinthe.Schema

Expand Down Expand Up @@ -154,8 +120,8 @@ defmodule Absinthe.Execution.SubscriptionTest do
end

setup_all do
{:ok, _} = PubSub.start_link()
{:ok, _} = Absinthe.Subscription.start_link(PubSub)
{:ok, _} = start_supervised(PubSub)
{:ok, _} = start_supervised({Absinthe.Subscription, [PubSub]})
:ok
end

Expand Down
37 changes: 37 additions & 0 deletions test/support/pubsub.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
defmodule PubSub do
@behaviour Absinthe.Subscription.Pubsub

def child_spec(opts) do
opts =
opts
|> Keyword.merge(keys: :unique, name: __MODULE__)

Registry.child_spec(opts)
end

def node_name() do
node()
end

def subscribe(topic) do
Registry.register(__MODULE__, topic, [])
:ok
end

def publish_subscription(topic, data) do
message = %{
topic: topic,
event: "subscription:data",
result: data
}

Registry.dispatch(__MODULE__, topic, fn entries ->
for {pid, _} <- entries, do: send(pid, {:broadcast, message})
end)
end

def publish_mutation(_proxy_topic, _mutation_result, _subscribed_fields) do
# this pubsub is local and doesn't support clusters
:ok
end
end

0 comments on commit 77a91d3

Please sign in to comment.