Sha256: 7eeb2b0c3a5aab3d7c2da25f8378b4c3dd7d61c21f5d5ccb985fe8ffef15bb40

Contents?: true

Size: 801 Bytes

Versions: 38

Compression:

Stored size: 801 Bytes

Contents

ENV["DB"] = "postgres"

require "thread"
require File.expand_path("../../../helper", __FILE__)
require "active_record/locking/fatalistic"

ActiveRecord::Migration.tap do |m|
  m.drop_table "things"
  m.create_table("things") do |t|
    t.string  :name
    t.string  :slug
  end
  m.add_index :things, :slug, :unique => true
end

class Thing < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, :use => :slugged
end

$things = 10.times.map do
  Thing.new :name => "a b c"
end

$mutex = Mutex.new

def save_thing
  thing = $mutex.synchronize do
    $things.pop
  end
  if thing.nil? then return end
  Thing.lock do
    thing.save!
    print "#{thing.friendly_id}\n"
  end
  true
end

2.times.map do
  Thread.new do
    while true do
      break unless save_thing
    end
  end
end.map(&:value)

Version data entries

38 entries across 33 versions & 4 rubygems

Version Path
mil_friendly_id-4.0.9.9 test/compatibility/threading/threading.rb
friendly_id-5.0.0.beta4 test/compatibility/threading/threading.rb
friendly_id-5.0.0.beta3 test/compatibility/threading/threading.rb
friendly_id-4.0.10.1 test/compatibility/threading/threading.rb
friendly_id-5.0.0.beta2 test/compatibility/threading/threading.rb
friendly_id-5.0.0.beta1 test/compatibility/threading/threading.rb
friendly_id-4.0.10 test/compatibility/threading/threading.rb
friendly_id-5.0.0.alpha.1 test/compatibility/threading/threading.rb
mil_friendly_id-4.0.9.8 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.8 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.7 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.6 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.5 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.4 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.3 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.2 test/compatibility/threading/threading.rb
geothird_friendly_id-4.0.9.1 test/compatibility/threading/threading.rb
friendly_id-4.1.0.beta.1 test/compatibility/threading/threading.rb
friendly_id-4.0.9 test/compatibility/threading/threading.rb
friendly_id-4.0.8 test/compatibility/threading/threading.rb