-
Notifications
You must be signed in to change notification settings - Fork 3
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
Benchmarks tests #18
Benchmarks tests #18
Conversation
8fd5ee3
to
fffb2c6
Compare
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.
Looking good!
@@ -2,17 +2,16 @@ defmodule ElixirBench.BenchmarksTest do | |||
use ElixirBench.DataCase | |||
alias ElixirBench.{Benchmarks, Benchmarks.Job} | |||
alias ElixirBench.Repos | |||
import ElixirBenchWeb.TestHelpers |
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.
this uhhh... shouldn't work? Afaik/iirc (macros aren't my strong suite admittedly) - but iirc you'd need to reuquire
a module to use its macros. I'm confused, CI passes 🤔
@michalmuskala ? :D
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.
import
implicitly does a require
. I'm not a huge fan of this behaviour, but it's probably far too late to change it now.
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.
😱 😱 😱 😢 😢 😢
Thanks Michał
@@ -2,17 +2,16 @@ defmodule ElixirBench.BenchmarksTest do | |||
use ElixirBench.DataCase | |||
alias ElixirBench.{Benchmarks, Benchmarks.Job} | |||
alias ElixirBench.Repos |
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.
alias unused
@@ -43,6 +43,22 @@ defmodule ElixirBenchWeb.TestHelpers do | |||
assert json_data == response | |||
end | |||
|
|||
defmacro assert_difference(queryable, value, do: expression) 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.
this is interesting! 👍 I think it's a cool macro - generally macros should be our last resort. Instead of macros we could have also used anonymous functions.
However, especially for test helpers macros can be super helpful as they have the benefit over "usual" functions that they don't show up in the stack trace.
so yeah, seems good - but careful with macros :)
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.
Nice! 😄 I couldn't think about a way to not evaluate the function before I count, so I needed the macro.
9e79aa1
to
ab58302
Compare
Tests are red because something you changed now seems to require erlang 20 🤔 |
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.
Looking good, couple of smaller suggestion and comments + those CI failures :)
lib/elixir_bench/benchmarks/job.ex
Outdated
@@ -46,6 +46,7 @@ defmodule ElixirBench.Benchmarks.Job do | |||
@create_fields [ | |||
:branch_name, | |||
:commit_sha, | |||
:repo_id, |
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.
it seems weird that we'd need to add this here the application was working before/is working - why would we need to add it here? 🤔
{:ok, runner} = Benchmarks.create_runner(%{name: name, api_key: api_key}) | ||
|
||
assert runner.id | ||
assert %Runner{name: ^name, api_key: ^api_key} = runner |
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 think this test might be enough for the runner tests - create_runner
just creates a changeset and tries to insert it. All the ways in which that could or could not go wrong is probably better tested in the runner unit tests by just checking if the changeset is valid.
That tests the core component this relies on, is faster and more focussed :)
test "return error if job not found" do | ||
binary_uuid = "99999999-9999-9999-9999-999999999999" | ||
assert {:error, :not_found} = Benchmarks.fetch_job_by_uuid(nil) | ||
assert {:error, :not_found} = Benchmarks.fetch_job_by_uuid(binary_uuid) |
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.
these tests are ok but I think in the future we don't need to write as many - these are a very thin wrapper around ecto's Repo fetch so we can generally trust that it works and I don't think they provide too much value :)
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.
Ok!
repo = insert(:repo) | ||
|
||
{:ok, job} = Benchmarks.create_job(repo, %{branch_name: "mm/benche", commit_sha: "ABC123"}) | ||
assert %Job{} = job |
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 don't think we need both the it's inserted test and it returned it test - both can be rolled into one test imo. Here we could also assert some attributes :)
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.
👍
|
||
# This does not work because in `measurement` the attributes job and benchmark | ||
# are not loaded `#Ecto.Association.NotLoaded` | ||
# assert_map_attr(my_measurement, measurement, [:id, :job, :benchmark]) |
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.
the association is not loaded, which means you need to do some form of preloading
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 refactored the tests, no need to preload anymore.
Benchmarks.create_job(repo, %{branch_name: "mm/benche", commit_sha: "ABC123"}) | ||
|
||
refute changeset.valid? | ||
assert_raise Postgrex.Error, fn -> |
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 didn't want this to raise an exception, thats why I added the verification for repo_id
in the Job.changeset. I found that the association attributes are handled by database constraints and they should be created by ecto when you have a references(target_table)
in the migration, so it returns {:error, reason}
in case of violation. We have all this, but it didn't act as I expected.
But I think this is ok for now. I will just put a FIXME on it.
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.
yeah we should fix it but probably in another ticket :)
Not a big fan of FIXME - rather create an issue for it
The tests are failing maybe beacaus now the tests cover function calls for |
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.
Looking good 👍
Benchmarks.create_job(repo, %{branch_name: "mm/benche", commit_sha: "ABC123"}) | ||
|
||
refute changeset.valid? | ||
assert_raise Postgrex.Error, fn -> |
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.
yeah we should fix it but probably in another ticket :)
Not a big fan of FIXME - rather create an issue for it
Yeah seems like it... maybe they didn't fail before because we didn't hit that path? Not sure... there were no dependency upgrades maybe just change the travis test matrix to only use erlang 20.3 or something :) |
c82591a
to
ddb9ade
Compare
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
ddb9ade
to
a39b9b1
Compare
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.
🎉
No description provided.