4 Rake.application.rake_require "tasks/delete_old_container_logs"
5 Rake::Task.define_task(:environment)
7 class DeleteOldContainerLogsTaskTest < ActiveSupport::TestCase
8 TASK_NAME = "db:delete_old_container_logs"
10 def log_uuids(*fixture_names)
11 fixture_names.map { |name| logs(name).uuid }
14 def run_with_expiry(clean_after)
15 Rails.configuration.clean_container_log_rows_after = clean_after
16 Rake::Task[TASK_NAME].reenable
17 Rake.application.invoke_task TASK_NAME
20 def check_log_existence(test_method, fixture_uuids)
21 uuids_now = Log.where("object_uuid LIKE :pattern AND event_type in ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat')", pattern: "%-dz642-%").map(&:uuid)
22 fixture_uuids.each do |expect_uuid|
23 send(test_method, uuids_now, expect_uuid)
27 test "delete all finished logs" do
28 uuids_to_keep = log_uuids(:stderr_for_running_container,
29 :crunchstat_for_running_container)
30 uuids_to_clean = log_uuids(:stderr_for_previous_container,
31 :crunchstat_for_previous_container,
32 :stderr_for_ancient_container,
33 :crunchstat_for_ancient_container)
35 check_log_existence(:assert_includes, uuids_to_keep)
36 check_log_existence(:refute_includes, uuids_to_clean)
39 test "delete old finished logs" do
40 uuids_to_keep = log_uuids(:stderr_for_running_container,
41 :crunchstat_for_running_container,
42 :stderr_for_previous_container,
43 :crunchstat_for_previous_container)
44 uuids_to_clean = log_uuids(:stderr_for_ancient_container,
45 :crunchstat_for_ancient_container)
46 run_with_expiry(360.days)
47 check_log_existence(:assert_includes, uuids_to_keep)
48 check_log_existence(:refute_includes, uuids_to_clean)