Sha256: 923f29fc5c576233f75535f4af3ffd750c31231537152e6e8b35b66ca498f38d

Contents?: true

Size: 886 Bytes

Versions: 2

Compression:

Stored size: 886 Bytes

Contents

require 'helper'

class TestThreadParent < MiniTest::Unit::TestCase

  include ThreadParent

  def setup
    Thread.current[:a] = 'a'
  end

  def test_can_have_parent
    thread = Thread.new { 'work' }.join
    assert_equal Thread.current, thread.parent
  end

  def test_can_find_thread_variable_in_parent
    thread = Thread.new { 'work' }.join
    assert_equal 'a', thread[:a]
  end

  def test_can_find_thread_variable_in_parents_parent
    Thread.new {
      Thread.new {
        assert_equal 'a', Thread.current[:a]
      }.join
    }.join
  end

  def test_can_override_parents_thread_variable
    thread = Thread.new {
      Thread.current[:a] = 'b'
    }.join

    assert_equal 'b', thread[:a]
  end

  def test_wont_break_parent_threads_scope
    Thread.new { Thread.current[:a] = 'b' }.join
    thread = Thread.new { 'work' }.join
    assert_equal('a', thread[:a])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thread-parent-1.0.1 test/test_thread_parent.rb
thread-parent-1.0.0 test/test_thread_parent.rb