Sha256: 66f2c91e18969a4ebc27153084c3f159ebd945dd96bb5fad9c6ef1a1f6e72012

Contents?: true

Size: 774 Bytes

Versions: 13

Compression:

Stored size: 774 Bytes

Contents

require 'locale'
require 'thread'
require 'test/unit'

class TestThread < Test::Unit::TestCase

  def setup
    Locale.init(:driver => :env)
    @mutex = Mutex.new
  end

  def invoke_thread(tag, sleep_time)
    Thread.start do
      @mutex.synchronize {
        ENV["LC_ALL"] = tag
        Locale.current
      }
      (1..10).each do |v|
#        puts "#{tag}: locale = #{Locale.current}"
        assert_equal tag, Locale.current.to_posix.to_s
        print "."
        $stdout.flush
        sleep sleep_time
      end
      Locale.clear # Clear this thread only.
    end
  end

  def test_thread
    th1 = invoke_thread("ja_JP.eucJP", 0.3)
    th2 = invoke_thread("zh_CN.UTF-8", 0.2)
    th3 = invoke_thread("en", 0.1)
    th1.join
    th2.join   
    th3.join
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locale-2.1.4 test/test_thread.rb
locale-2.1.3 test/test_thread.rb
locale-2.1.2 test/test_thread.rb
locale-2.1.1 test/test_thread.rb
locale-2.1.0 test/test_thread.rb
locale-2.0.9 test/test_thread.rb
locale-2.0.8 test/test_thread.rb
locale-2.0.7 test/test_thread.rb
locale-2.0.6 test/test_thread.rb
locale-2.0.5 test/test_thread.rb
locale-2.0.3 test/test_thread.rb
locale-2.0.4 test/test_thread.rb
locale-2.0.2 test/test_thread.rb