Skip to content

Commit

Permalink
Disable the "time hack"
Browse files Browse the repository at this point in the history
Also added some troubleshooting logs
  • Loading branch information
huylenq committed Jan 12, 2021
1 parent d2efdfc commit 79cac85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 9 additions & 1 deletion lib/td/client/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,23 @@ def wait(*args)
wait_interval = args[1] || 2
deadline = monotonic_clock + timeout if timeout
timeout_klass = Class.new(Exception)
puts ">>> TIMEOUT: #{timeout}"
puts ">>> WAIT_INTERVAL: #{wait_interval}"
begin
if timeout
if deadline <= monotonic_clock
raise timeout_klass, "timeout (#{timeout}) exceeded wait_interval=#{wait_interval}"
end
end
puts ">>> START SLEEP"
sleep wait_interval
puts ">>> END SLEEP"
detail ? update_status! : update_progress!
yield self if block_given?
puts ">>> CHECK YIELDING"
if block_given?
puts ">>> YIELD"
yield self
end
rescue timeout_klass
raise Timeout::Error, $!.message
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Timeout::Error, EOFError,
Expand Down
11 changes: 8 additions & 3 deletions spec/td/client/model_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,20 @@ def change_job_status(status)
end

it 'calls a given block in every wait_interval second' do
now = 1_400_000_000
allow(self).to receive(:sleep){|arg| now += arg }
allow(Process).to receive(:clock_gettime){ now }

# now = 1_400_000_000
# allow(self).to receive(:sleep){|arg| now += arg }
# allow(Process).to receive(:clock_gettime){ now }

expect { |b|
begin
thread = Thread.start {
puts ">>> START THREAD"
job.wait(nil, 2, &b)
}
puts ">>> EXPECT START SLEEP"
sleep 6
puts ">>> EXPECT END SLEEP"
change_job_status(Job::STATUS_SUCCESS)
thread.join(1)
expect(thread).to be_stop
Expand Down

0 comments on commit 79cac85

Please sign in to comment.