1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
8 Rake.application.rake_require "tasks/delete_old_job_logs"
9 Rake::Task.define_task(:environment)
11 class DeleteOldJobLogsTaskTest < ActiveSupport::TestCase
12 TASK_NAME = "db:delete_old_job_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
25 Log.where("object_uuid LIKE :pattern AND event_type = :etype",
26 pattern: "_____-8i9sb-_______________",
30 def check_existence(test_method, fixture_uuids)
31 uuids_now = job_stderr_logs.map(&:uuid)
32 fixture_uuids.each do |expect_uuid|
33 send(test_method, uuids_now, expect_uuid)
37 test "delete all logs" do
38 uuids_to_keep = log_uuids(:crunchstat_for_running_job)
39 uuids_to_clean = log_uuids(:crunchstat_for_previous_job,
40 :crunchstat_for_ancient_job)
42 check_existence(:assert_includes, uuids_to_keep)
43 check_existence(:refute_includes, uuids_to_clean)
46 test "delete only old logs" do
47 uuids_to_keep = log_uuids(:crunchstat_for_running_job,
48 :crunchstat_for_previous_job)
49 uuids_to_clean = log_uuids(:crunchstat_for_ancient_job)
50 run_with_expiry(360.days)
51 check_existence(:assert_includes, uuids_to_keep)
52 check_existence(:refute_includes, uuids_to_clean)