File: test_super_call_site_caching.rb

package info (click to toggle)
jruby 1.5.6-9
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 45,088 kB
  • ctags: 77,093
  • sloc: ruby: 398,491; java: 170,202; yacc: 3,782; xml: 2,529; sh: 299; tcl: 40; makefile: 35; ansic: 23
file content (107 lines) | stat: -rw-r--r-- 2,190 bytes parent folder | download | duplicates (8)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'test/unit'

class SuperCachedCallSiteTest < Test::Unit::TestCase
  class ApplicationController
    attr_reader :path
    def initialize
      @path = []
    end

    def render
      @path << "ApplicationController"
    end
  end

  class FooController < ApplicationController
    def self.expected_path
      ["SpecialRenderMethod", "FooController", "ApplicationController"]
    end

    def render
      @path << "FooController"
      super
    end
  end

  class BarController < ApplicationController
    def self.expected_path
      ["SpecialRenderMethod", "BarController", "ApplicationController"]
    end

    def render
      @path << "BarController"
      super
    end
  end

  module SpecialRenderMethod
    def render(*args,&block)
      @path << "SpecialRenderMethod"
      super(*args,&block)
    end
  end

  module SomeOtherRenderStuff
  end

  module ExtraSpecialRenderMethod
    include SomeOtherRenderStuff
    include SpecialRenderMethod
  end

  def assert_paths(mod)
    [FooController, BarController].each do |controller_class|
      controller = controller_class.new
      (class << controller; self; end).class_eval do
        include mod
      end
      controller.render
      assert_equal controller_class.expected_path, controller.path
    end
  end

  def test_super_call_paths_without_extra_module_inserted
    assert_paths SpecialRenderMethod
  end

  def test_super_call_paths_with_extra_module_inserted
    assert_paths ExtraSpecialRenderMethod
  end
  
  # JRUBY-4568: Concurrency issue with SuperCallSite
  class Top
    def foo
      "foo"
    end

    def bar
      "bar"
    end
  end

  class Bottom < Top
    body = proc do
      super()
    end

    define_method :foo, &body
    define_method :bar, &body
  end

  def test_super_callsite_concurrency
    assert_nothing_raised do
      (1..10).to_a.map do
        Thread.new do
          10_000.times do
            begin
              Thread.main.raise unless Bottom.new.foo == "foo"
              Thread.main.raise unless Bottom.new.bar == "bar"
            rescue
              Thread.main.raise $!
            end
          end
        end
      end.each {|t| t.join}
    end
  end
end