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

Benchmarks tests #18

Merged
merged 5 commits into from
May 28, 2018
Merged

Conversation

tallysmartins
Copy link
Member

No description provided.

@coveralls
Copy link

coveralls commented May 22, 2018

Coverage Status

Coverage increased (+18.3%) to 62.903% when pulling a39b9b1 on tallysmartins:benchmarks_tests into 91c2ae6 on elixir-bench:master.

Copy link
Member

@PragTob PragTob left a 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
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

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

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

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 :)

Copy link
Member Author

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.

@tallysmartins tallysmartins force-pushed the benchmarks_tests branch 2 times, most recently from 9e79aa1 to ab58302 Compare May 24, 2018 22:07
@PragTob
Copy link
Member

PragTob commented May 25, 2018

Tests are red because something you changed now seems to require erlang 20 🤔

Copy link
Member

@PragTob PragTob left a 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 :)

@@ -46,6 +46,7 @@ defmodule ElixirBench.Benchmarks.Job do
@create_fields [
:branch_name,
:commit_sha,
:repo_id,
Copy link
Member

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

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)
Copy link
Member

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 :)

Copy link
Member Author

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

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 :)

Copy link
Member Author

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])
Copy link
Member

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

Copy link
Member Author

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 ->
Copy link
Member Author

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.

Copy link
Member

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

@tallysmartins
Copy link
Member Author

tallysmartins commented May 25, 2018

The tests are failing maybe beacaus now the tests cover function calls for Bcrypt inside the ElixirBench.Benchmarks.Runner module, but idk why this didn't break before. 🤔

Copy link
Member

@PragTob PragTob left a 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 ->
Copy link
Member

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

@PragTob
Copy link
Member

PragTob commented May 26, 2018

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 :)

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>
@tallysmartins tallysmartins changed the title WIP: Benchmarks tests Benchmarks tests May 27, 2018
Copy link
Member

@PragTob PragTob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@PragTob PragTob merged commit ddb5107 into elixir-bench:master May 28, 2018
@tallysmartins tallysmartins deleted the benchmarks_tests branch May 28, 2018 12:36
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.

None yet

4 participants