<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="253313" data-post-id="253313">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="trisolaran" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/120/23748_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  trisolaran
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="andreyuhai" data-post="11" data-topic="48378">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/andreyuhai/48/23551_2.png" class="avatar"> andreyuhai:</div>
<blockquote>
<p>Also when I’ve inspected the actual <code>Oban.Job</code> that was passed to <code>perform/1</code> from <code>perform_job</code>, I see that the <code>id</code> is <code>nil</code>.</p>
</blockquote>
</aside>
<p>That’s expected, <code>perform_job/3</code> doesn’t insert the job in the DB (it’s used to unit test a worker) so the <code>id</code> of the job will be <code>nil</code></p>
<aside class="quote no-group" data-username="andreyuhai" data-post="11" data-topic="48378">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/andreyuhai/48/23551_2.png" class="avatar"> andreyuhai:</div>
<blockquote>
<p>The above snippet somehow throws the ArgumentError I shared <a href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/2" rel="nofollow">above</a>.</p>
</blockquote>
</aside>
<p>Yeah I verified this error with my own code and I was able to reproduce it.</p>
<p>Here’s what I strongly believe it’s going on:</p>
<ol>
<li><code>:inline</code> testing mode uses the <code>Oban.Queue.InlineEngine</code>, which doesn’t touch the DB, while <code>:manual</code> testing mode uses the <code>Oban.Queue.BasicEngine</code>, which inserts jobs in the DB</li>
<li><code>perform_job/3</code> is always supposed to run in <code>:inline</code> mode using the <code>InlineEngine</code>, if it accidentally uses the <code>BasicEngine</code>, the error you encountered will be triggered, namely it will try to update the state of a job that was never inserted in the DB</li>
<li>Therefore, when you call <code>perform_job/3</code>, it sets <code>testing: :inline</code> in the config here: <a href="https://github.com/sorentwo/oban/blob/fdeb0001bbacb60c4686b86ca0610c7f7508d357/lib/oban/testing.ex#L233" class="inline-onebox" rel="noopener nofollow ugc">oban/lib/oban/testing.ex at fdeb0001bbacb60c4686b86ca0610c7f7508d357 · oban-bg/oban · GitHub</a> which is then used here: <a href="https://github.com/sorentwo/oban/blob/fdeb0001bbacb60c4686b86ca0610c7f7508d357/lib/oban/config.ex#L359" class="inline-onebox" rel="noopener nofollow ugc">oban/lib/oban/config.ex at fdeb0001bbacb60c4686b86ca0610c7f7508d357 · oban-bg/oban · GitHub</a> to enforce the usage of the <code>InlineEngine</code> (the correct one), regardless of the <code>testing</code> mode set in your main config. So you can have <code>testing: :manual</code> in your config and still have <code>perform_job/3</code> run correctly using the <code>InlineEngine</code>.</li>
<li>This works well as long as you don’t use <code>with_testing_mode(:manual, ...)</code>. Reason is that <code>with_testing_mode/2</code> sets the engine to use in the process dictionary here: <a href="https://github.com/sorentwo/oban/blob/9b4861354f0189d548f4d5cd89273bc98f8eaede/lib/oban/testing.ex#L396" class="inline-onebox" rel="noopener nofollow ugc">oban/lib/oban/testing.ex at 9b4861354f0189d548f4d5cd89273bc98f8eaede · oban-bg/oban · GitHub</a> and this takes precedence over the engine set by <code>perform_job/3</code> . The overwrite happens here: <a href="https://github.com/sorentwo/oban/blob/1e0f61a913a2ba52c985675383e2f7a180119ac5/lib/oban/queue/engine.ex#L232" class="inline-onebox" rel="noopener nofollow ugc">oban/lib/oban/queue/engine.ex at 1e0f61a913a2ba52c985675383e2f7a180119ac5 · oban-bg/oban · GitHub</a></li>
</ol>
<p>Long story short: <code>perform_job/3</code> always tries to use the <code>InlineEngine</code>, cause it fails otherwise, but <code> with_testing_mode/2</code> gets in the way end enforces the usage of the <code>BasicEngine</code>, which is the wrong one and causes the issue.</p>
<p>This seems to be a bug, <code>perform_job/3</code> should ignore the engine set by <code>with_testing_mode/2</code>. Although, to be honest, I see little use for explicitly setting the test mode to <code>:manual</code> and then calling <code>perform_job/3</code>. If you’re using manual mode you’re expected to insert jobs in the <code>DB</code> and execute them with <code>drain_queue/2</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253313" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-253313" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253313"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="253314" data-post-id="253314">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="andreyuhai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/andreyuhai/120/23551_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  andreyuhai
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you for taking the time to try it! <img src="https://forum.elixirforum.com/images/emoji/apple/bowing_man.png?v=15" title=":bowing_man:" class="emoji" alt=":bowing_man:" loading="lazy" width="20" height="20"><br>
I think you’re right, as <a class="mention" href="/u/shanesveller" rel="nofollow">@shanesveller</a> has mentioned in Slack channel that he’s got a <a href="https://github.com/sorentwo/oban/pull/694" rel="noopener nofollow ugc">PR for that</a>. I’ll try from that branch and see if it solves my problem.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253314" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-253314" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253314"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="253315" data-post-id="253315">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="trisolaran" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/120/23748_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  trisolaran
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="andreyuhai" data-post="13" data-topic="48378">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/andreyuhai/48/23551_2.png" class="avatar"> andreyuhai:</div>
<blockquote>
<p>Thank you for taking the time to try it! <img src="https://forum.elixirforum.com/images/emoji/apple/bowing_man.png?v=15" title=":bowing_man:" class="emoji" alt=":bowing_man:" loading="lazy" width="20" height="20"></p>
</blockquote>
</aside>
<p>wasted time apparently, since the bug is already known and there’s a PR for it… Well, it happens.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253315" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-253315" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253315"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="253317" data-post-id="253317">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="andreyuhai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/andreyuhai/120/23551_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  andreyuhai
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="trisolaran" data-post="14" data-topic="48378">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/48/23748_2.png" class="avatar"> trisolaran:</div>
<blockquote>
<p>time apparently, since the bug is already known and there’s a PR for it… Well, it happens.</p>
</blockquote>
</aside>
<p>Sorry, I didn’t know about it to let you know beforehand. I just saw the message this morning. <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253317" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-253317" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253317"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="253318" data-post-id="253318">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="trisolaran" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/120/23748_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  trisolaran
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey no worries! Glad you found the solution to your problem. Also, it was an instructive deep dive into oban’s testing code, so not a complete waste of time <img src="https://forum.elixirforum.com/images/emoji/apple/smile_cat.png?v=15" title=":smile_cat:" class="emoji" alt=":smile_cat:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253318" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-253318" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253318"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="253320" data-post-id="253320">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hubertlepicki" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hubertlepicki/120/6822_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hubertlepicki
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This is precisely the reason why I submitted this PR a while ago:</p>
<p><a href="https://github.com/beam-telemetry/telemetry/pull/111" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/beam-telemetry/telemetry/pull/111</a></p>
<p>This hasn’t been merged yet, but it’s the use case I had in mind and also experienced, that a lot of libraries do not provide any additional instrumentation in addition to telemetry events. It’s not great fit, since Telemetry was never meant to do instrumentation, hence the callbacks detaching mechanism. But life is life, and libraries do use it this way.</p>
<p>So my idea is to add option to specify durable handlers. If you have better idea I’d be very much interested to hear.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253320" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-253320" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253320"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="253348" data-post-id="253348">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="al2o3cr" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/120/3457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  al2o3cr
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think you called out exactly what I’m thinking in a previous comment on the issue linked to that PR:</p>
<p><a href="https://github.com/beam-telemetry/telemetry/issues/106#issuecomment-1090072574" class="onebox" target="_blank" rel="noopener nofollow">https://github.com/beam-telemetry/telemetry/issues/106#issuecomment-1090072574</a></p>
<blockquote>
<p>It’s almost like we need a second event dispatch mechanism, along Telemetry, where events are durable (i.e. do not detach), execute in predictable and defined way, and failures in handlers result in overall request failure as well.</p>
</blockquote>
<p>IMO that second mechanism is <em>not</em> <code>:telemetry</code>, it’s a different thing entirely with different requirements and tradeoffs.</p>
<p>The big difference is what happens when things go wrong: <code>:telemetry</code> takes the position that “uptime with missing logs” is better than “downtime with 100% complete logs” under heavy load or crashing handler functions. A hypothetical “callback registry” or “event bus” would likely make the opposite choice.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253348" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/oban-how-to-properly-assert-on-enqueued-jobs/48378/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-253348" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253348"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>