Sha256: c8040902ab55015bdca02dac3017bd52d022df096415578f4c6de12cebd94b57

Contents?: true

Size: 1.23 KB

Versions: 25

Compression:

Stored size: 1.23 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

require 'test_helper'
require 'support/apps/active_record/active_record'
require 'fileutils'

class RailsActiveRecordDatabaseMissingTest < Minitest::Test
  def setup
    skip unless ENV['DATABASE_URL']

    @old_url = ENV['DATABASE_URL']
    SQLite3::Database.new('/tmp/test.db')
    ENV['DATABASE_URL'] = 'sqlite3:///tmp/test.db'

    @connection = ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
    ActiveRecord::Migration.suppress_messages do
      ActiveRecord::Migration.run(CreateBlocks, direction: :up)
    end
  end

  def teardown
    ActiveRecord::Base.remove_connection(@connection)
    ENV['DATABASE_URL'] = @old_url
  end

  def test_error_on_missing_database
    assert_raises(ActiveRecord::StatementInvalid) do
      Instana::Tracer.start_or_continue_trace(:ar_test, {}) do
        b = Block.new
        FileUtils.rm('/tmp/test.db')
        b.save!
      end
    end

    spans = ::Instana.processor.queued_spans
    assert_equal 3, spans.length
    span = find_first_span_by_name(spans, :activerecord)

    assert_equal 1, span[:ec]
    assert span[:data][:activerecord][:error].include?("SQLite3::ReadOnlyException: attempt to write a readonly database")
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
instana-1.211.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.210.1 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.210.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.8 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.7 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.6 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.5 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.4 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.3 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.2 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.1 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.0.pre3 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.0.pre2 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.209.0.pre1 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.208.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.207.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.206.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.205.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.204.0 test/instrumentation/rails_active_record_database_missing_test.rb
instana-1.204.0.pre3 test/instrumentation/rails_active_record_database_missing_test.rb