@@ -27,6 +27,54 @@ class JobsLifecycleTest < ActiveSupport::TestCase
27
27
assert_equal 2 , SolidQueue ::Job . finished . count
28
28
end
29
29
30
+ test "enqueue and run jobs that fail without retries" do
31
+ RaisingJob . perform_later ( RuntimeError , "A" )
32
+ RaisingJob . perform_later ( RuntimeError , "B" )
33
+ jobs = SolidQueue ::Job . last ( 2 )
34
+
35
+ @dispatcher . start
36
+ @worker . start
37
+
38
+ wait_for_jobs_to_finish_for ( 3 . seconds )
39
+
40
+ message = "raised RuntimeError for the 1st time"
41
+ assert_equal [ "A: #{ message } " , "B: #{ message } " ] , JobBuffer . values . sort
42
+
43
+ assert_empty SolidQueue ::Job . finished
44
+ end
45
+
46
+ test "enqueue and run jobs that fail and succeed after retrying" do
47
+ RaisingJob . perform_later ( RaisingJob ::DefaultError , "A" , 5 ) # this will fail after being retried
48
+ RaisingJob . perform_later ( RaisingJob ::DefaultError , "B" )
49
+
50
+ @dispatcher . start
51
+ @worker . start
52
+
53
+ wait_for_jobs_to_finish_for ( 3 . seconds )
54
+
55
+ messages_from_a = 1 . upto ( 3 ) . collect { |i | "A: raised RaisingJob::DefaultError for the #{ i . ordinalize } time" }
56
+ messages_from_b = [ "B: raised RaisingJob::DefaultError for the 1st time" , "Successfully completed job" ]
57
+
58
+ assert_equal messages_from_a + messages_from_b , JobBuffer . values . sort
59
+
60
+ assert_equal 4 , SolidQueue ::Job . finished . count # B + its retry + 2 retries of A
61
+ assert_equal 1 , SolidQueue ::FailedExecution . count
62
+ end
63
+
64
+ test "enqueue and run jobs that fail and it's discarded" do
65
+ RaisingJob . perform_later ( RaisingJob ::DiscardableError , "A" )
66
+
67
+ @dispatcher . start
68
+ @worker . start
69
+
70
+ wait_for_jobs_to_finish_for ( 1 . seconds )
71
+
72
+ assert_equal [ "A: raised RaisingJob::DiscardableError for the 1st time" ] , JobBuffer . values . sort
73
+
74
+ assert_equal 1 , SolidQueue ::Job . finished . count
75
+ assert_equal 0 , SolidQueue ::FailedExecution . count
76
+ end
77
+
30
78
test "schedule and run jobs" do
31
79
AddToBufferJob . set ( wait : 1 . day ) . perform_later ( "I'm scheduled" )
32
80
AddToBufferJob . set ( wait : 3 . days ) . perform_later ( "I'm scheduled later" )
0 commit comments