From 1084cda3fbc7499259aad696898924216dd554fb Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Fri, 6 Oct 2023 14:53:09 -0400 Subject: [PATCH 1/2] Fixes #1 We want to start collecting environment data so that we can better track and share benchmarks for https://github.com/fastruby/fast-ruby --- app/controllers/reports_controller.rb | 5 ++- ...0231006184214_add_attributes_to_reports.rb | 7 ++++ db/schema.rb | 14 ++++---- test/controllers/reports_controller_test.rb | 34 +++++++++++++++++-- 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20231006184214_add_attributes_to_reports.rb diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index c360f27..cabb773 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -41,7 +41,10 @@ def create end end - rep = Report.create report: JSON.generate(ary) + rep = Report.create report: JSON.generate(ary), + ruby: input["ruby"], + os: input["os"], + arch: input["arch"] options = input["options"] || {} diff --git a/db/migrate/20231006184214_add_attributes_to_reports.rb b/db/migrate/20231006184214_add_attributes_to_reports.rb new file mode 100644 index 0000000..cca10a5 --- /dev/null +++ b/db/migrate/20231006184214_add_attributes_to_reports.rb @@ -0,0 +1,7 @@ +class AddAttributesToReports < ActiveRecord::Migration[7.0] + def change + add_column :reports, :ruby, :string + add_column :reports, :os, :string + add_column :reports, :arch, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0252bad..2c206f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,24 +2,26 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# This file is the source Rails uses to define your schema when running `rails -# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2016_04_13_035657) do - +ActiveRecord::Schema[7.0].define(version: 2023_10_06_184214) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "reports", id: :serial, force: :cascade do |t| t.text "report" t.boolean "compare" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + t.string "ruby" + t.string "os" + t.string "arch" end end diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index d40afa7..35399c5 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -64,7 +64,7 @@ class ReportsControllerTest < ActionController::TestCase }] } DATA - + post :create, body: data assert_equal "400", @response.code @@ -79,10 +79,40 @@ class ReportsControllerTest < ActionController::TestCase }] } DATA - + post :create, body: data assert_equal "400", @response.code + end + + test "environment variables are sent, processed, and saved" do + data = { + "ruby" => "3.2.1", + "os" => "Linux", + "arch" => "x86_64", + "entries" => [ + { + "name" => "test", + "ips" => 10.1, + "central_tendency" => 10.1, + "error" => 23666, + "stddev" => 0.3, + "microseconds" => 3322, + "iterations" => 221, + "cycles" => 16 + } + ] + } + + post :create, body: data.to_json + + require "byebug"; byebug + rep = JSON.parse @response.body + + report = Report.find_from_short_id rep["id"] + assert_equal "3.2.1", report.ruby + assert_equal "Linux", report.os + assert_equal "x86_64", report.arch end end From 763667647dd48a4b1c29b46b2b1712e96b43f68b Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 9 Oct 2023 19:48:56 -0400 Subject: [PATCH 2/2] Update test/controllers/reports_controller_test.rb Co-authored-by: Ariel Juodziukynas --- test/controllers/reports_controller_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index 35399c5..8f9b34c 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -106,7 +106,6 @@ class ReportsControllerTest < ActionController::TestCase post :create, body: data.to_json - require "byebug"; byebug rep = JSON.parse @response.body report = Report.find_from_short_id rep["id"]