@@ -495,6 +495,45 @@ public void ChangeState_DoesNotInvokeApplyStateFilters_WhenFiltersDisabled()
495
495
_transaction . Verify ( x => x . Commit ( ) ) ;
496
496
}
497
497
498
+ [ Fact ]
499
+ public void ChangeState_WithTransaction_PassesTheGivenTransaction_AndDoesNotCommitTheImplicitOne ( )
500
+ {
501
+ _context . Transaction = new Mock < JobStorageTransaction > ( ) ;
502
+ var stateChanger = CreateStateChanger ( ) ;
503
+
504
+ stateChanger . ChangeState ( _context . Object ) ;
505
+
506
+ _stateMachine . Verify ( x => x . ApplyState ( It . Is < ApplyStateContext > (
507
+ ctx => ctx . Transaction == _context . Transaction . Object ) ) ) ;
508
+
509
+ _connection . Verify ( x => x . CreateWriteTransaction ( ) , Times . Never ) ;
510
+ _transaction . Verify ( x => x . Commit ( ) , Times . Never ) ;
511
+ }
512
+
513
+ [ Fact ]
514
+ public void ChangeState_WithTransaction_DoesNotCommitAndDoesNotDisposeTheExplicitTransaction ( )
515
+ {
516
+ _context . Transaction = new Mock < JobStorageTransaction > ( ) ;
517
+ var stateChanger = CreateStateChanger ( ) ;
518
+
519
+ stateChanger . ChangeState ( _context . Object ) ;
520
+
521
+ _context . Transaction . Verify ( x => x . Commit ( ) , Times . Never ) ;
522
+ _context . Transaction . Verify ( x => x . Dispose ( ) , Times . Never ) ;
523
+ }
524
+
525
+ [ Fact ]
526
+ public void ChangeState_WithTransaction_AcquiresATransactionLevelLockInstead ( )
527
+ {
528
+ _context . Transaction = new Mock < JobStorageTransaction > ( ) ;
529
+ var stateChanger = CreateStateChanger ( ) ;
530
+
531
+ stateChanger . ChangeState ( _context . Object ) ;
532
+
533
+ _context . Transaction . Verify ( x => x . AcquireDistributedLock ( $ "job:{ JobId } :state-lock", It . IsAny < TimeSpan > ( ) ) ) ;
534
+ _connection . Verify ( x => x . AcquireDistributedLock ( It . IsAny < string > ( ) , It . IsAny < TimeSpan > ( ) ) , Times . Never ) ;
535
+ }
536
+
498
537
private BackgroundJobStateChanger CreateStateChanger ( )
499
538
{
500
539
return new BackgroundJobStateChanger ( _filterProvider . Object , _stateMachine . Object ) ;
0 commit comments