44 let ( :cron_job ) do
55 job_fixture do
66 include Sentry ::Cron ::MonitorCheckIns
7- sentry_monitor_check_ins
7+ sentry_monitor_check_ins slug : "test-cron-ok-job"
88
99 def perform
1010 "ok"
@@ -15,28 +15,45 @@ def perform
1515 let ( :failing_cron_job ) do
1616 job_fixture do
1717 include Sentry ::Cron ::MonitorCheckIns
18- sentry_monitor_check_ins
18+ sentry_monitor_check_ins (
19+ slug : "test-cron-fail-job" ,
20+ monitor_config : Sentry ::Cron ::MonitorConfig . from_crontab ( "5 * * * *" )
21+ )
1922
2023 def perform
2124 raise "boom from failing_cron_job spec"
2225 end
2326 end
2427 end
2528
26- it "emits in_progress and ok check-ins for a successful job" do
29+ it "emits in_progress and ok check-ins with correct slug for a successful job" do
2730 cron_job . perform_later
2831 drain
2932
3033 check_ins = sentry_events . select { |e | e . is_a? ( Sentry ::CheckInEvent ) }
3134 expect ( check_ins . size ) . to eq ( 2 )
3235
3336 first , second = check_ins
34- expect ( first . to_h ) . to include ( type : "check_in" , status : :in_progress )
35- expect ( second . to_h ) . to include ( type : "check_in" , status : :ok , check_in_id : first . check_in_id )
37+ expect ( first . to_h ) . to include (
38+ type : "check_in" ,
39+ status : :in_progress ,
40+ monitor_slug : "test-cron-ok-job"
41+ )
42+ expect ( second . to_h ) . to include (
43+ type : "check_in" ,
44+ status : :ok ,
45+ check_in_id : first . check_in_id ,
46+ monitor_slug : "test-cron-ok-job"
47+ )
3648 expect ( second . to_h ) . to have_key ( :duration )
3749 end
3850
39- it "emits in_progress and error check-ins plus an exception event for a failing job" do
51+ it "returns the job's perform value through the cron mixin" do
52+ result = cron_job . perform_now
53+ expect ( result ) . to eq ( "ok" )
54+ end
55+
56+ it "emits in_progress and error check-ins with monitor_config for a failing job" do
4057 expect do
4158 failing_cron_job . perform_later
4259 drain
@@ -46,6 +63,10 @@ def perform
4663 error_events = sentry_events . select { |e | e . is_a? ( Sentry ::ErrorEvent ) }
4764
4865 expect ( check_ins . map { |e | e . to_h [ :status ] } ) . to eq ( %i[ in_progress error ] )
66+ expect ( check_ins . map { |e | e . to_h [ :monitor_slug ] } ) . to all ( eq ( "test-cron-fail-job" ) )
67+ expect ( check_ins . map { |e | e . to_h [ :monitor_config ] } ) . to all ( include (
68+ schedule : { type : :crontab , value : "5 * * * *" }
69+ ) )
4970 expect ( error_events . size ) . to eq ( 1 )
5071 end
5172end
0 commit comments