Skip to content

Using this gem in another rails gem for testing #9

@brendon

Description

@brendon

Hi there @fractaledmind, I was just wondering if there was anything special required in order to use this gem to assist with SQLite3::BusyException in testing another gem?

I'm working on https://github.com/brendon/positioning and have run into conflicts in the following test when I ramp up the number of threads:

class TestTransactionSafety < Minitest::Test
  def test_no_duplicate_row_values
    ActiveRecord::Base.connection_handler.clear_all_connections!

    list = List.create name: "List"
    students = []

    10.times do
      threads = 200.times.map do
        Thread.new do
          ActiveRecord::Base.connection_pool.with_connection do
            students << list.authors.create(name: "Student", type: "Author::Student")
          end
        end
      end
      threads.each(&:join)
    end

    assert_equal (1..students.length).to_a, list.authors.map(&:position)

    list.destroy
  end
end

I've put together an advisory lock based on a file lock technique I saw in the Advisory Lock gem but was still encountering errors and your mention of the default treatment of transactions with the sqlite3 gem in Rails made me think that perhaps that's what's going on here too.

Not the most fun thing to try and figure out unfortunately :D

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions