-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite predictions pubsub tests #2129
Conversation
{registry_key, predictions} = GenServer.call(server, {:subscribe, stream_topic}) | ||
{registry_key, predictions} = GenServer.call(__MODULE__, {:subscribe, stream_topic}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why not leave __MODULE__
as a default argument to this function? Then we can inject different dependencies to test if we'd like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are moving away from DI and towards using Mox. We don't need to inject variables in dynamically. That is, it will never be called with a second argument.
def init(_) do | ||
Phoenix.PubSub.subscribe(@predictions_phoenix_pub_sub, "predictions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why are we making this compile-time instead of a runtime option? It's conventional for callbacks like init
to actually configure the process they're starting dynamically from the options being passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're using Mox and determining the implementation at compile time.
def clear(keys) do | ||
GenServer.cast(__MODULE__, {:remove, Enum.map(fetch(keys), & &1.id)}) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I would also suggest making __MODULE__
an argument to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, we aren't doing DI. We will never need to message a different GenServer.
@@ -0,0 +1,24 @@ | |||
defmodule Predictions.Store.Behaviour do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: could we come up with a different name for this behaviour? I find it confusing to read code with @behaviour Behaviour
everywhere, it makes it seem like this is some kind of generic library code for behaviours but it seems like it's actually a Predictions Store Behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think it is pretty straightforward. Predictions.Store
implements the Predictions.Store.Behaviour
. Makes it so that any time I want to find the custom behaviour being implemented, I know right where to look.
{Phoenix.PubSub, [name: Predictions.PubSub]}, | ||
{Phoenix.PubSub, [name: @predictions_phoenix_pub_sub]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same suggestion re: dynamic vs static configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are moving away from DI and toward using Mox. That's 50% of the purpose of this PR.
The tests around starting streams seem flaky. I'm going to write a helper that does assertions on a retry basis so we don't have to try to sleep for the 'right' amount of time. |
No ticket, this is just the test rewrite to go along with not showing predictions with no departure time.
Please reference: https://www.notion.so/mbta-downtown-crossing/Mocking-External-Dependencies-625665802fb84c8fa6e6edfa030d273f