Sha256: 1ab3b0ca3ca67afdde53f22ab43355f695ad30a82970e17369723dc995f19a88

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

require 'helper'

class TestThreadParent < MiniTest::Unit::TestCase

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

  def test_is_a_thread_parent
    thread = Thread.new { 'work' }
    assert_kind_of Thread, thread
  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.parents[:a]
  end

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

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

    assert_equal 'b', thread.parents[: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.parents[:a])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thread-parent-1.0.2 test/test_thread_parent.rb