4 Rake.application.rake_require "tasks/delete_old_job_logs"
5 Rake::Task.define_task(:environment)
7 class DeleteOldJobLogsTaskTest < ActiveSupport::TestCase
8 TASK_NAME = "db:delete_old_job_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_job_log_rows_after = clean_after
16 Rake::Task[TASK_NAME].reenable
17 Rake.application.invoke_task TASK_NAME
21 Log.where("object_uuid LIKE :pattern AND event_type = :etype",
22 pattern: "_____-8i9sb-_______________",
26 def check_existence(test_method, fixture_uuids)
27 uuids_now = job_stderr_logs.map(&:uuid)
28 fixture_uuids.each do |expect_uuid|
29 send(test_method, uuids_now, expect_uuid)
33 test "delete all logs" do
34 uuids_to_keep = log_uuids(:crunchstat_for_running_job)
35 uuids_to_clean = log_uuids(:crunchstat_for_previous_job,
36 :crunchstat_for_ancient_job)
38 check_existence(:assert_includes, uuids_to_keep)
39 check_existence(:refute_includes, uuids_to_clean)
42 test "delete only old logs" do
43 uuids_to_keep = log_uuids(:crunchstat_for_running_job,
44 :crunchstat_for_previous_job)
45 uuids_to_clean = log_uuids(:crunchstat_for_ancient_job)
46 run_with_expiry(360.days)
47 check_existence(:assert_includes, uuids_to_keep)
48 check_existence(:refute_includes, uuids_to_clean)