parent
0414b5cc50
commit
12604aa399
@ -0,0 +1,54 @@
|
|||||||
|
From 4f4f8a705a8e713bceee8cacca52e9bce22e28dc Mon Sep 17 00:00:00 2001
|
||||||
|
From: "yuuji.yaginuma" <yuuji.yaginuma@gmail.com>
|
||||||
|
Date: Wed, 18 Dec 2019 19:00:29 +0900
|
||||||
|
Subject: [PATCH] Make `LoadInterlockAwareMonitor` work in Ruby 2.7
|
||||||
|
|
||||||
|
Currently `LoadInterlockAwareMonitorTest` does not pass with Ruby 2.7 [1].
|
||||||
|
This is due to the refactoring of the `monitor` done in Ruby 2.7 [2].
|
||||||
|
|
||||||
|
With this refactoring, the behavior of the method has changed from the
|
||||||
|
expected behavior in `LoadInterlockAwareMonitor`.
|
||||||
|
|
||||||
|
This patch also overwrites `synchronize` so that
|
||||||
|
`LoadInterlockAwareMonitor` works as expected.
|
||||||
|
|
||||||
|
[1]: https://buildkite.com/rails/rails/builds/65877#eec47af5-7595-47cb-97c0-30c589716176/996-2743
|
||||||
|
[2]: https://bugs.ruby-lang.org/issues/16255
|
||||||
|
---
|
||||||
|
.../load_interlock_aware_monitor.rb | 18 ++++++++++++++++++
|
||||||
|
1 file changed, 18 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb b/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb
|
||||||
|
index a8455c00483f..480c34c64017 100644
|
||||||
|
--- a/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb
|
||||||
|
+++ b/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb
|
||||||
|
@@ -7,11 +7,29 @@ module Concurrency
|
||||||
|
# A monitor that will permit dependency loading while blocked waiting for
|
||||||
|
# the lock.
|
||||||
|
class LoadInterlockAwareMonitor < Monitor
|
||||||
|
+ EXCEPTION_NEVER = { Exception => :never }.freeze
|
||||||
|
+ EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze
|
||||||
|
+ private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE
|
||||||
|
+
|
||||||
|
# Enters an exclusive section, but allows dependency loading while blocked
|
||||||
|
def mon_enter
|
||||||
|
mon_try_enter ||
|
||||||
|
ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
|
||||||
|
end
|
||||||
|
+
|
||||||
|
+ def synchronize
|
||||||
|
+ Thread.handle_interrupt(EXCEPTION_NEVER) do
|
||||||
|
+ mon_enter
|
||||||
|
+
|
||||||
|
+ begin
|
||||||
|
+ Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
|
||||||
|
+ yield
|
||||||
|
+ end
|
||||||
|
+ ensure
|
||||||
|
+ mon_exit
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,24 @@
|
|||||||
|
From e9425abe33924623b1dce62bd817eace757c2b4e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Phil Ross <phil.ross@gmail.com>
|
||||||
|
Date: Fri, 29 Dec 2017 12:47:10 +0000
|
||||||
|
Subject: [PATCH] Update to TZInfo v2.0.0
|
||||||
|
|
||||||
|
Co-authored-by: Jared Beck <jared@jaredbeck.com>
|
||||||
|
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
|
||||||
|
---
|
||||||
|
time_zone_test.rb | 2 +-
|
||||||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
|
||||||
|
index 4b5f3dceee6f..646b9e1d3199 100644
|
||||||
|
--- a/activesupport/test/time_zone_test.rb
|
||||||
|
+++ b/activesupport/test/time_zone_test.rb
|
||||||
|
@@ -22,7 +29,7 @@ def test_local_to_utc
|
||||||
|
|
||||||
|
def test_period_for_local
|
||||||
|
zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]
|
||||||
|
- assert_instance_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000))
|
||||||
|
+ assert_kind_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000))
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveSupport::TimeZone::MAPPING.each_key do |name|
|
@ -0,0 +1,119 @@
|
|||||||
|
From e9425abe33924623b1dce62bd817eace757c2b4e Mon Sep 17 00:00:00 2001
|
||||||
|
From: Phil Ross <phil.ross@gmail.com>
|
||||||
|
Date: Fri, 29 Dec 2017 12:47:10 +0000
|
||||||
|
Subject: [PATCH] Update to TZInfo v2.0.0
|
||||||
|
|
||||||
|
Co-authored-by: Jared Beck <jared@jaredbeck.com>
|
||||||
|
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
|
||||||
|
---
|
||||||
|
time_with_zone.rb | 20 +++++++++++++++-----
|
||||||
|
values/time_zone.rb | 14 ++++++--------
|
||||||
|
2 files changed, 21 insertions(+), 13 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
|
||||||
|
index 3be5f6f7b595..9a4c33ab0f19 100644
|
||||||
|
--- a/activesupport/lib/active_support/time_with_zone.rb
|
||||||
|
+++ b/activesupport/lib/active_support/time_with_zone.rb
|
||||||
|
@@ -57,12 +57,12 @@ def initialize(utc_time, time_zone, local_time = nil, period = nil)
|
||||||
|
|
||||||
|
# Returns a <tt>Time</tt> instance that represents the time in +time_zone+.
|
||||||
|
def time
|
||||||
|
- @time ||= period.to_local(@utc)
|
||||||
|
+ @time ||= incorporate_utc_offset(@utc, utc_offset)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a <tt>Time</tt> instance of the simultaneous time in the UTC timezone.
|
||||||
|
def utc
|
||||||
|
- @utc ||= period.to_utc(@time)
|
||||||
|
+ @utc ||= incorporate_utc_offset(@time, -utc_offset)
|
||||||
|
end
|
||||||
|
alias_method :comparable_time, :utc
|
||||||
|
alias_method :getgm, :utc
|
||||||
|
@@ -104,13 +104,13 @@ def dst?
|
||||||
|
# Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
|
||||||
|
# Time.zone.now.utc? # => false
|
||||||
|
def utc?
|
||||||
|
- period.offset.abbreviation == :UTC || period.offset.abbreviation == :UCT
|
||||||
|
+ zone == "UTC" || zone == "UCT"
|
||||||
|
end
|
||||||
|
alias_method :gmt?, :utc?
|
||||||
|
|
||||||
|
# Returns the offset from current time to UTC time in seconds.
|
||||||
|
def utc_offset
|
||||||
|
- period.utc_total_offset
|
||||||
|
+ period.observed_utc_offset
|
||||||
|
end
|
||||||
|
alias_method :gmt_offset, :utc_offset
|
||||||
|
alias_method :gmtoff, :utc_offset
|
||||||
|
@@ -132,7 +132,7 @@ def formatted_offset(colon = true, alternate_utc_string = nil)
|
||||||
|
# Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
|
||||||
|
# Time.zone.now.zone # => "EST"
|
||||||
|
def zone
|
||||||
|
- period.zone_identifier.to_s
|
||||||
|
+ period.abbreviation
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a string of the object's date, time, zone, and offset from UTC.
|
||||||
|
@@ -514,6 +514,16 @@ def method_missing(sym, *args, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
+ SECONDS_PER_DAY = 86400
|
||||||
|
+
|
||||||
|
+ def incorporate_utc_offset(time, offset)
|
||||||
|
+ if time.kind_of?(Date)
|
||||||
|
+ time + Rational(offset, SECONDS_PER_DAY)
|
||||||
|
+ else
|
||||||
|
+ time + offset
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
def get_period_and_ensure_valid_local_time(period)
|
||||||
|
# we don't want a Time.local instance enforcing its own DST rules as well,
|
||||||
|
# so transfer time values to a utc constructor if necessary
|
||||||
|
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
|
||||||
|
index 90830b89bda3..2e5d9d3e9d4c 100644
|
||||||
|
--- a/activesupport/lib/active_support/values/time_zone.rb
|
||||||
|
+++ b/activesupport/lib/active_support/values/time_zone.rb
|
||||||
|
@@ -203,7 +203,7 @@ def seconds_to_utc_offset(seconds, colon = true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_tzinfo(name)
|
||||||
|
- TZInfo::Timezone.new(MAPPING[name] || name)
|
||||||
|
+ TZInfo::Timezone.get(MAPPING[name] || name)
|
||||||
|
end
|
||||||
|
|
||||||
|
alias_method :create, :new
|
||||||
|
@@ -273,7 +273,7 @@ def load_country_zones(code)
|
||||||
|
memo
|
||||||
|
end
|
||||||
|
else
|
||||||
|
- create(tz_id, nil, TZInfo::Timezone.new(tz_id))
|
||||||
|
+ create(tz_id, nil, TZInfo::Timezone.get(tz_id))
|
||||||
|
end
|
||||||
|
end.flatten(1).sort!
|
||||||
|
end
|
||||||
|
@@ -302,11 +302,7 @@ def initialize(name, utc_offset = nil, tzinfo = nil)
|
||||||
|
|
||||||
|
# Returns the offset of this time zone from UTC in seconds.
|
||||||
|
def utc_offset
|
||||||
|
- if @utc_offset
|
||||||
|
- @utc_offset
|
||||||
|
- else
|
||||||
|
- tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
|
||||||
|
- end
|
||||||
|
+ @utc_offset || tzinfo&.current_period&.base_utc_offset
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a formatted string of the offset from UTC, or an alternative
|
||||||
|
@@ -498,7 +494,9 @@ def yesterday
|
||||||
|
# represented by +self+. Returns a Time.utc() instance -- if you want an
|
||||||
|
# ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
|
||||||
|
def utc_to_local(time)
|
||||||
|
- tzinfo.utc_to_local(time)
|
||||||
|
+ tzinfo.utc_to_local(time).yield_self do |t|
|
||||||
|
+ Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, t.sec_fraction)
|
||||||
|
+ end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Adjust the given time to the simultaneous time in UTC. Returns a
|
Loading…
Reference in new issue