Mercurial > hg > orthanc
comparison UnitTestsSources/MultiThreadingTests.cpp @ 2581:8da2cffc2378 jobs
JobsRegistry::Cancel()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 May 2018 17:33:19 +0200 |
parents | 055d7d4a823f |
children | 1b6a6d80b6f2 |
comparison
equal
deleted
inserted
replaced
2580:055d7d4a823f | 2581:8da2cffc2378 |
---|---|
321 return false; | 321 return false; |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 | 325 |
326 static bool CheckErrorCode(Orthanc::JobsRegistry& registry, | |
327 const std::string& id, | |
328 Orthanc::ErrorCode code) | |
329 { | |
330 Orthanc::JobInfo s; | |
331 if (registry.GetJobInfo(s, id)) | |
332 { | |
333 return code == s.GetStatus().GetErrorCode(); | |
334 } | |
335 else | |
336 { | |
337 return false; | |
338 } | |
339 } | |
340 | |
341 | |
326 TEST(JobsRegistry, Priority) | 342 TEST(JobsRegistry, Priority) |
327 { | 343 { |
328 JobsRegistry registry; | 344 JobsRegistry registry; |
329 | 345 |
330 std::string i1, i2, i3, i4; | 346 std::string i1, i2, i3, i4; |
606 job.MarkSuccess(); | 622 job.MarkSuccess(); |
607 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | 623 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); |
608 } | 624 } |
609 | 625 |
610 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | 626 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); |
627 } | |
628 | |
629 | |
630 TEST(JobsRegistry, Cancel) | |
631 { | |
632 JobsRegistry registry; | |
633 | |
634 std::string id; | |
635 registry.Submit(id, new DummyJob(), 10); | |
636 | |
637 ASSERT_FALSE(registry.Cancel("nope")); | |
638 | |
639 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
640 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
641 | |
642 ASSERT_TRUE(registry.Cancel(id)); | |
643 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); | |
644 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
645 | |
646 ASSERT_TRUE(registry.Cancel(id)); | |
647 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); | |
648 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
649 | |
650 ASSERT_TRUE(registry.Resubmit(id)); | |
651 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
652 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
653 | |
654 { | |
655 JobsRegistry::RunningJob job(registry, 0); | |
656 ASSERT_TRUE(job.IsValid()); | |
657 | |
658 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
659 | |
660 job.MarkSuccess(); | |
661 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
662 } | |
663 | |
664 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
665 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
666 | |
667 ASSERT_TRUE(registry.Cancel(id)); | |
668 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Success)); | |
669 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
670 | |
671 registry.Submit(id, new DummyJob(), 10); | |
672 | |
673 { | |
674 JobsRegistry::RunningJob job(registry, 0); | |
675 ASSERT_TRUE(job.IsValid()); | |
676 ASSERT_EQ(id, job.GetId()); | |
677 | |
678 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
679 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
680 | |
681 job.MarkCanceled(); | |
682 } | |
683 | |
684 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); | |
685 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
686 | |
687 ASSERT_TRUE(registry.Resubmit(id)); | |
688 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
689 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
690 | |
691 ASSERT_TRUE(registry.Pause(id)); | |
692 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Paused)); | |
693 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
694 | |
695 ASSERT_TRUE(registry.Cancel(id)); | |
696 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); | |
697 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
698 | |
699 ASSERT_TRUE(registry.Resubmit(id)); | |
700 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Pending)); | |
701 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
702 | |
703 { | |
704 JobsRegistry::RunningJob job(registry, 0); | |
705 ASSERT_TRUE(job.IsValid()); | |
706 ASSERT_EQ(id, job.GetId()); | |
707 | |
708 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
709 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Running)); | |
710 | |
711 job.MarkRetry(500); | |
712 } | |
713 | |
714 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Retry)); | |
715 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_Success)); | |
716 | |
717 ASSERT_TRUE(registry.Cancel(id)); | |
718 ASSERT_TRUE(CheckState(registry, id, Orthanc::JobState_Failure)); | |
719 ASSERT_TRUE(CheckErrorCode(registry, id, ErrorCode_CanceledJob)); | |
611 } | 720 } |
612 | 721 |
613 | 722 |
614 | 723 |
615 | 724 |