Skip to content

Commit 9388f4a

Browse files
committed
add more logging while waiting
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
1 parent ee4a5a9 commit 9388f4a

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

lib/openhab/rspec/helpers.rb

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,20 +364,35 @@ def load_transforms
364364
# @param [String] addon_id The addon id, such as "binding-mqtt"
365365
# @param [true,false] wait Wait until OSGi has confirmed the bundle is installed and running before returning.
366366
# @param [String,Array<String>] ready_markers Array of ready marker types to wait for.
367+
# @param [Numeric] install_timeout Max seconds to wait for addon installation.
367368
# @param [Numeric] ready_timeout Max seconds to wait for ready markers.
368369
# The addon's bundle id is used as the identifier.
369370
# @return [void]
370371
#
371-
def install_addon(addon_id, wait: true, ready_markers: nil, ready_timeout: 30)
372+
def install_addon(addon_id, wait: true, ready_markers: nil, install_timeout: 30, ready_timeout: 30)
372373
service_filter = "(component.name=org.openhab.core.karafaddons)"
373374
addon_service = OSGi.service("org.openhab.core.addon.AddonService", filter: service_filter)
374375
addon_service.install(addon_id)
375376
return unless wait
376377

377378
addon = nil
379+
install_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
380+
install_deadline = install_start + install_timeout
381+
next_install_log_at = install_start + 5
378382
loop do
379383
addon = addon_service.get_addon(addon_id, nil)
380-
break if addon.installed?
384+
break if addon&.installed?
385+
386+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
387+
if now >= next_install_log_at
388+
elapsed = (now - install_start).round(1)
389+
logger.warn("Still waiting for addon to install: #{addon_id} (elapsed=#{elapsed}s, timeout=#{install_timeout}s)") # rubocop:disable Layout/LineLength
390+
next_install_log_at = now + 5
391+
end
392+
393+
if now >= install_deadline
394+
raise "Timed out after #{install_timeout}s waiting for addon installation: #{addon_id}"
395+
end
381396

382397
sleep 0.25
383398
end
@@ -396,16 +411,26 @@ def install_addon(addon_id, wait: true, ready_markers: nil, ready_timeout: 30)
396411
end
397412

398413
rs = OSGi.service("org.openhab.core.service.ReadyService")
399-
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + ready_timeout
414+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
415+
deadline = start + ready_timeout
416+
next_log_at = start + 5
400417

401418
loop do
419+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
402420
pending_markers = ready_markers.reject { |rm| rs.ready?(rm) }
403421
break if pending_markers.empty?
404422

405-
if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
406-
pending_marker_text = pending_markers
407-
.map { |rm| "#{rm.type}(#{rm.identifier})" }
408-
.join(", ")
423+
pending_marker_text = pending_markers
424+
.map { |rm| "#{rm.type}(#{rm.identifier})" }
425+
.join(", ")
426+
427+
if now >= next_log_at
428+
elapsed = (now - start).round(1)
429+
logger.warn("Still waiting for ready markers for #{addon_id} (elapsed=#{elapsed}s, timeout=#{ready_timeout}s): #{pending_marker_text}") # rubocop:disable Layout/LineLength
430+
next_log_at = now + 5
431+
end
432+
433+
if now >= deadline
409434
logger.warn("Timed out waiting for ready markers for #{addon_id}: #{pending_marker_text}")
410435
raise "Timed out after #{ready_timeout}s waiting for ready markers for #{addon_id}: #{pending_marker_text}"
411436
end

0 commit comments

Comments
 (0)