Skip to content

Commit

Permalink
Merge 4d84c81 into 424f013
Browse files Browse the repository at this point in the history
  • Loading branch information
tallysmartins committed Aug 9, 2018
2 parents 424f013 + 4d84c81 commit 41a18d4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/elixir_bench/benchmarks/job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule ElixirBench.Benchmarks.Job do
field :claimed_at, :utc_datetime
field :completed_at, :utc_datetime
field :log, :string
field :exit_status, :integer

field :branch_name, :string
field :commit_message, :string
Expand All @@ -41,7 +42,8 @@ defmodule ElixirBench.Benchmarks.Job do
:cpu_count,
# TODO: change to a string memory
# :memory_mb,
:log
:log,
:exit_status
]

@create_fields [
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_bench_web/schema/content_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defmodule ElixirBenchWeb.Schema.ContentTypes do
field :claimed_at, :datetime
field :completed_at, :datetime
field :log, :string
field :exit_status, :integer

field :repo_slug, :string do
resolve(fn %{repo_id: repo_id}, _, %{context: %{loader: loader}} ->
Expand Down
14 changes: 14 additions & 0 deletions priv/repo/migrations/20180809140205_add_exit_status_to_job.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule ElixirBench.Repo.Migrations.AddExitStatusToJob do
use Ecto.Migration

def change do
alter table(:jobs) do
add :exit_status, :integer, default: nil
end

# assume all existent jobs has finished with success
execute """
UPDATE jobs SET exit_status = 0 WHERE exit_status IS NULL;
""", "" # nothing on down
end
end
32 changes: 29 additions & 3 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
alias ElixirBench.{Benchmarks, Repos}

github_client = Application.get_env(:elixir_bench, :github_client)

if(github_client != ElixirBench.Github.ClientInMemory) do
raise """
\n
#############################################################################
Please, before running this seed you need to set :github_client to
ElixirBench.Github.ClientInMemory in your config/mix.#{Mix.env()}
This is necessary because our current scripts are not yet stable enough, so
you need to use local calls to mocked data instead of reaching the Github
servers in order to fetch the config.yml configuration for the repositories.
#############################################################################
"""
end

{:ok, runner} = Benchmarks.create_runner(%{name: "test-runner", api_key: "test"})
{:ok, repo} = Repos.create_repo(%{owner: "elixir-ecto", name: "ecto"})

{:ok, %{id: job_id}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
{:ok, %{id: job_id1}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
{:ok, %{id: job_id2}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})

{:ok, %{id: ^job_id} = job} = Benchmarks.claim_job(runner)
{:ok, %{id: failed_job_id}} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})
{:ok, _pending_job} = Benchmarks.create_job(repo, %{branch_name: "mm/benches", commit_sha: "207b2a0"})

data = %{
"elixir_version" => "1.5.2",
Expand All @@ -17,6 +35,7 @@ data = %{
"log" => """
[now] Oh how ward it was to run this benchmark!
""",
"exit_status" => 0,
"measurements" => %{
"insert_mysql/insert_plain" => %{
"average" => 393.560253365004,
Expand Down Expand Up @@ -73,4 +92,11 @@ data = %{
}
}

:ok = Benchmarks.submit_job(job, data)
{:ok, %{id: ^job_id1} = job1} = Benchmarks.claim_job(runner)
:ok = Benchmarks.submit_job(job1, data)

{:ok, %{id: ^job_id2} = job2} = Benchmarks.claim_job(runner)
:ok = Benchmarks.submit_job(job2, data)

{:ok, %{id: ^failed_job_id} = failed_job} = Benchmarks.claim_job(runner)
:ok = Benchmarks.submit_job(failed_job, %{data | "log" => "Error, exiting with status 127", "exit_status" => 127, "measurements" => nil})
8 changes: 5 additions & 3 deletions test/elixir_bench_web/schema/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,20 @@ defmodule ElixirBenchWeb.SchemaTest do

describe "job query" do
test "fetch job by id", context do
job = insert(:job)
job = insert(:job, %{exit_status: 1})

query = """
job (id: "#{job.id}") {
id
id,
exit_status
}
"""

json_data = %{
"data" => %{
"job" => %{
"id" => "#{job.id}"
"id" => "#{job.id}",
"exit_status" => 1
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/support/factory/elixir_bench_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ defmodule ElixirBench.Factory do
"log" => """
[now] Oh how ward it was to run this benchmark!
""",
"exit_status" => 0,
"measurements" => %{
"insert_mysql/insert_plain" => %{
"average" => 393.560253365004,
Expand Down

0 comments on commit 41a18d4

Please sign in to comment.