1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
8 Rake.application.rake_require "tasks/delete_old_container_logs"
9 Rake::Task.define_task(:environment)
11 class DeleteOldContainerLogsTaskTest < ActiveSupport::TestCase
12 TASK_NAME = "db:delete_old_container_logs"
14 def log_uuids(*fixture_names)
15 fixture_names.map { |name| logs(name).uuid }
18 def run_with_expiry(clean_after)
19 Rails.configuration.Containers.Logging.MaxAge = clean_after
20 Rake::Task[TASK_NAME].reenable
21 Rake.application.invoke_task TASK_NAME
24 def check_log_existence(test_method, fixture_uuids)
25 uuids_now = Log.where("object_uuid LIKE :pattern AND event_type in ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat')", pattern: "%-dz642-%").map(&:uuid)
26 fixture_uuids.each do |expect_uuid|
27 send(test_method, uuids_now, expect_uuid)
31 test "delete all finished logs" do
32 uuids_to_keep = log_uuids(:stderr_for_running_container,
33 :crunchstat_for_running_container)
34 uuids_to_clean = log_uuids(:stderr_for_previous_container,
35 :crunchstat_for_previous_container,
36 :stderr_for_ancient_container,
37 :crunchstat_for_ancient_container)
39 check_log_existence(:assert_includes, uuids_to_keep)
40 check_log_existence(:refute_includes, uuids_to_clean)
43 test "delete old finished logs" do
44 uuids_to_keep = log_uuids(:stderr_for_running_container,
45 :crunchstat_for_running_container,
46 :stderr_for_previous_container,
47 :crunchstat_for_previous_container)
48 uuids_to_clean = log_uuids(:stderr_for_ancient_container,
49 :crunchstat_for_ancient_container)
50 run_with_expiry(360.days)
51 check_log_existence(:assert_includes, uuids_to_keep)
52 check_log_existence(:refute_includes, uuids_to_clean)