Skip to content
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

Merged
merged 17 commits into from
Jul 25, 2024

Conversation

anthonyshull
Copy link
Contributor

@anthonyshull anthonyshull commented Jul 16, 2024

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

@anthonyshull anthonyshull changed the title Rewrite mostly working Rewrite predictions pubsub tests Jul 16, 2024
@anthonyshull anthonyshull marked this pull request as ready for review July 17, 2024 20:40
@anthonyshull anthonyshull requested a review from a team as a code owner July 17, 2024 20:40
@anthonyshull anthonyshull requested a review from bklebe July 17, 2024 20:40
Comment on lines -41 to +43
{registry_key, predictions} = GenServer.call(server, {:subscribe, stream_topic})
{registry_key, predictions} = GenServer.call(__MODULE__, {:subscribe, stream_topic})
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +59 to +60
def init(_) do
Phoenix.PubSub.subscribe(@predictions_phoenix_pub_sub, "predictions")
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +25 to 27
def clear(keys) do
GenServer.cast(__MODULE__, {:remove, Enum.map(fetch(keys), & &1.id)})
end
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines -18 to +20
{Phoenix.PubSub, [name: Predictions.PubSub]},
{Phoenix.PubSub, [name: @predictions_phoenix_pub_sub]},
Copy link
Contributor

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

Copy link
Contributor Author

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.

@anthonyshull anthonyshull requested a review from bklebe July 18, 2024 16:12
@anthonyshull anthonyshull marked this pull request as draft July 24, 2024 15:10
@anthonyshull
Copy link
Contributor Author

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.

@anthonyshull anthonyshull marked this pull request as ready for review July 24, 2024 18:43
@anthonyshull anthonyshull merged commit 9b1b4ad into main Jul 25, 2024
17 checks passed
@anthonyshull anthonyshull deleted the ags/predictions-channel-test-rewrite branch July 25, 2024 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants