File: test_thread.rb

package info (click to toggle)
ruby-locale 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 444 kB
  • ctags: 293
  • sloc: ruby: 3,203; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 774 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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