Class: Flaky::Commands::History
- Inherits:
-
Object
- Object
- Flaky::Commands::History
- Defined in:
- lib/flaky/commands/history.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(spec_location:) ⇒ History
constructor
A new instance of History.
Constructor Details
Instance Method Details
#execute ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/flaky/commands/history.rb', line 13 def execute conn = @db.connection file, line = parse_location(@spec_location) conditions = ["tf.spec_file LIKE ?"] params = ["%#{file}%"] if line conditions << "tf.line_number = ?" params << line end rows = conn.execute(<<~SQL, params) SELECT tf.spec_file, tf.line_number, tf.description, tf.seed, tf.job_name, tf.branch, tf.failed_at, cr.workflow_id FROM test_failures tf JOIN ci_runs cr ON cr.workflow_id = tf.workflow_id WHERE #{conditions.join(" AND ")} ORDER BY tf.failed_at DESC SQL if rows.empty? puts "No failures found matching '#{@spec_location}'." return end first = rows.first puts "Failure history for #{first['spec_file']}:#{first['line_number']}" puts " #{first['description']}\n\n" puts format("%-20s %-8s %-30s %s", "Date", "Seed", "Job", "Workflow") puts "-" * 100 rows.each do |row| puts format("%-20s %-8d %-30s %s", row["failed_at"], row["seed"], row["job_name"], row["workflow_id"]) end puts "\nTotal failures: #{rows.length}" seeds = rows.map { |r| r["seed"] }.uniq puts "Unique seeds: #{seeds.join(', ')}" puts "\nTo reproduce: rake flaky:stress[#{first['spec_file']}:#{first['line_number']},10,#{seeds.first},true]" ensure @db.close end |