diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2017-10-31 18:46:32 +0300 |
---|---|---|
committer | Andrew Newdigate <andrew@gitlab.com> | 2017-10-31 18:46:32 +0300 |
commit | 959ead4bfbc31c74de93263119589545cbbe9858 (patch) | |
tree | d4e303a2db55a47bed8a7fb2be1573a0fde28965 | |
parent | 12225a57d6f14a69e41df59bf089a102dcc8d470 (diff) |
Workaround for timecop deadline problems
-rw-r--r-- | lib/gitlab/gitaly_client.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb index 71f067e8a99..fd3b1463c34 100644 --- a/lib/gitlab/gitaly_client.rb +++ b/lib/gitlab/gitaly_client.rb @@ -32,8 +32,8 @@ module Gitlab # The default timeout on all Gitaly calls DEFAULT_TIMEOUT = Sidekiq.server? ? 0.seconds : 50.seconds - FAST_TIMEOUT = 30.seconds - MEDIUM_TIMEOUT = 40.seconds + FAST_TIMEOUT = 10.seconds + MEDIUM_TIMEOUT = 30.seconds MUTEX = Mutex.new private_constant :MUTEX @@ -52,7 +52,7 @@ module Gitlab klass = Gitaly.const_get(name.to_s.camelcase.to_sym).const_get(:Stub) addr = address(storage) addr = addr.sub(%r{^tcp://}, '') if URI(addr).scheme == 'tcp' - klass.new(addr, :this_channel_is_insecure, timeout: DEFAULT_TIMEOUT) + klass.new(addr, :this_channel_is_insecure) end end end @@ -116,9 +116,19 @@ module Gitlab feature = feature_stack && feature_stack[0] metadata['call_site'] = feature.to_s if feature - deadline = Time.now + timeout if !timeout.nil? && timeout > 0 + result = { metadata: metadata } - { metadata: metadata, deadline: deadline } + return result unless !timeout.nil? && timeout > 0 + + # Do not use `Time.now` for deadline calculation, since it + # will be affected by Timecop in some tests, but grpc's c-core + # uses system time instead of timecop's time, so tests will fail + # `Time.at(Process.clock_gettime(Process::CLOCK_REALTIME))` will + # circumvent timecop + deadline = Time.at(Process.clock_gettime(Process::CLOCK_REALTIME)) + timeout + result[:deadline] = deadline + + result end def self.token(storage) |