Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ci-queue (0.93.0)
ci-queue (0.94.0)
logger

GEM
Expand Down
6 changes: 4 additions & 2 deletions ruby/lib/ci/queue/redis/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ def shutdown!
end
end

def tick!(id, lease)
send_message(TICK_COMMAND, id: id, lease: lease.to_s)
def tick!(id, lease = nil)
payload = { id: id }
payload[:lease] = lease.to_s if lease
send_message(TICK_COMMAND, **payload)
@restart_attempts = 0
rescue IOError, Errno::EPIPE => error
@restart_attempts = (@restart_attempts || 0) + 1
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/ci/queue/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module CI
module Queue
VERSION = '0.93.0'
VERSION = '0.94.0'
DEV_SCRIPTS_ROOT = ::File.expand_path('../../../../../redis', __FILE__)
RELEASE_SCRIPTS_ROOT = ::File.expand_path('../redis', __FILE__)
end
Expand Down
38 changes: 32 additions & 6 deletions ruby/test/ci/queue/redis/heartbeat_process_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def write(*parts)
end
end

class PipedHeartbeatProcess < CI::Queue::Redis::Base::HeartbeatProcess
attr_reader :pipe

def initialize(pipe, *args)
super(*args)
@pipe = pipe
end

def boot!; end
def restart!; end
end

def setup
@hp = CI::Queue::Redis::Base::HeartbeatProcess.new(
'redis://localhost:6379/0',
Expand Down Expand Up @@ -71,12 +83,12 @@ def test_restart_counter_resets_after_success
end

def test_tick_does_not_allocate_tick_marker_string
@hp.instance_variable_set(:@pipe, FakePipe.new)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding PipedHeartbeatProcess to remove usage of instance_variable_set

@hp.tick!("test_id", "lease_id") # warm up any one-time caches
hp = PipedHeartbeatProcess.new(FakePipe.new, 'redis://localhost:6379/0', 'zset', 'owners', 'leases')
hp.tick!("test_id", "lease_id") # warm up any one-time caches

ObjectSpace.trace_object_allocations_start
begin
@hp.tick!("test_id", "lease_id")
hp.tick!("test_id", "lease_id")
ensure
ObjectSpace.trace_object_allocations_stop
end
Expand All @@ -97,15 +109,29 @@ def test_tick_does_not_allocate_tick_marker_string

def test_tick_sends_valid_tick_payload
pipe = FakePipe.new
@hp.instance_variable_set(:@pipe, pipe)
hp = PipedHeartbeatProcess.new(pipe, 'redis://localhost:6379/0', 'zset', 'owners', 'leases')

@hp.tick!("test_id", "lease_id")
hp.tick!("test_id", "lease_id")

raw = pipe.buffer
header_size = [0].pack("L").bytesize
size = raw.byteslice(0, header_size).unpack1("L")
payload = raw.byteslice(header_size, size)

assert_equal(["tick!", { "id" => "test_id", "lease" => "lease_id" }], JSON.parse(payload))
end

def test_tick_without_lease_omits_lease_from_payload
pipe = FakePipe.new
hp = PipedHeartbeatProcess.new(pipe, 'redis://localhost:6379/0', 'zset', 'owners', 'leases')

hp.tick!("test_id")

raw = pipe.buffer
header_size = [0].pack("L").bytesize
size = raw.byteslice(0, header_size).unpack1("L")
payload = raw.byteslice(header_size, size)

assert_equal ["tick!", { "id" => "test_id", "lease" => "lease_id" }], JSON.parse(payload)
assert_equal(["tick!", { "id" => "test_id" }], JSON.parse(payload))
end
end
Loading