Sha256: 3307b0149910f4dbb010387011a6d7dd91e2bb675dc4346840ef98b3f1b7662a

Contents?: true

Size: 1.62 KB

Versions: 19

Compression:

Stored size: 1.62 KB

Contents

# encoding: UTF-8

require File.expand_path("helper", File.dirname(__FILE__))

class TestForkSafety < Test::Unit::TestCase

  include Helper::Client
  include Helper::Skipable

  driver(:ruby, :hiredis) do
    def test_fork_safety
      redis = Redis.new(OPTIONS)
      redis.set "foo", 1

      child_pid = fork do
        begin
          # InheritedError triggers a reconnect,
          # so we need to disable reconnects to force
          # the exception bubble up
          redis.without_reconnect do
            redis.set "foo", 2
          end
        rescue Redis::InheritedError
          exit 127
        end
      end

      _, status = Process.wait2(child_pid)

      assert_equal 127, status.exitstatus
      assert_equal "1", redis.get("foo")

    rescue NotImplementedError => error
      raise unless error.message =~ /fork is not available/
      return skip(error.message)
    end

    def test_fork_safety_with_enabled_inherited_socket
      redis = Redis.new(OPTIONS.merge(:inherit_socket => true))
      redis.set "foo", 1

      child_pid = fork do
        begin
          # InheritedError triggers a reconnect,
          # so we need to disable reconnects to force
          # the exception bubble up
          redis.without_reconnect do
            redis.set "foo", 2
          end
        rescue Redis::InheritedError
          exit 127
        end
      end

      _, status = Process.wait2(child_pid)

      assert_equal 0, status.exitstatus
      assert_equal "2", redis.get("foo")

    rescue NotImplementedError => error
      raise unless error.message =~ /fork is not available/
      return skip(error.message)
    end
  end
end

Version data entries

19 entries across 18 versions & 7 rubygems

Version Path
finsync_redis-3.3.5 test/fork_safety_test.rb
redis-3.3.5 test/fork_safety_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/fork_safety_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/fork_safety_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/fork_safety_test.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/fork_safety_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/test/fork_safety_test.rb
redis-3.3.3 test/fork_safety_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/test/fork_safety_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/test/fork_safety_test.rb
redis-3.3.2 test/fork_safety_test.rb
redis-3.3.1 test/fork_safety_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/test/fork_safety_test.rb
redis-3.3.0 test/fork_safety_test.rb
discourse-redis-3.2.2 test/fork_safety_test.rb
redis-3.2.2 test/fork_safety_test.rb
redis-3.2.1 test/fork_safety_test.rb
redis-3.2.0 test/fork_safety_test.rb
redis-3.1.0 test/fork_safety_test.rb