Mercurial > hg > orthanc-transfers
changeset 96:3e73a429d8fa
fix unit tests
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Tue, 09 Dec 2025 18:12:15 +0100 |
| parents | b83139953899 |
| children | ee8a86e2d3cb |
| files | Framework/DownloadArea.cpp Framework/DownloadArea.h |
| diffstat | 2 files changed, 34 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/DownloadArea.cpp Tue Dec 09 16:17:40 2025 +0100 +++ b/Framework/DownloadArea.cpp Tue Dec 09 18:12:15 2025 +0100 @@ -47,14 +47,13 @@ bool simulate_; public: - InstanceToCommit(DownloadArea::Instance* instance /* transfer ownership */, bool simulate) : + InstanceToCommit(DownloadArea::Instance* instance /* does not take ownership */, bool simulate) : instance_(instance), simulate_(simulate) {} virtual ~InstanceToCommit() { - delete instance_; } DownloadArea::Instance* GetInstance() @@ -161,16 +160,13 @@ content.empty() ? NULL : content.c_str(), content.size(), false)) { - LOG(ERROR) << "Cannot import a transfered DICOM instance into Orthanc: " - << info_.GetId(); - throw Orthanc::OrthancException(Orthanc::ErrorCode_CorruptedFile); + throw Orthanc::OrthancException(Orthanc::ErrorCode_CorruptedFile, "Cannot import a transfered DICOM instance into Orthanc: " + info_.GetId()); } } } else { - LOG(ERROR) << "Bad MD5 sum in a transfered DICOM instance: " << info_.GetId(); - throw Orthanc::OrthancException(Orthanc::ErrorCode_CorruptedFile); + throw Orthanc::OrthancException(Orthanc::ErrorCode_CorruptedFile, "Bad MD5 sum in a transfered DICOM instance: " + info_.GetId()); } } @@ -283,20 +279,35 @@ while (true) { - std::unique_ptr<DownloadArea::InstanceToCommit> instanceToCommit(dynamic_cast<DownloadArea::InstanceToCommit*>(that->instancesToCommit_.Dequeue(0))); - if (instanceToCommit.get() == NULL || that->workersShouldStop_) // that's the signal to exit the thread + try { - LOG(INFO) << "Commit thread has completed"; - return; + std::unique_ptr<DownloadArea::InstanceToCommit> instanceToCommit(dynamic_cast<DownloadArea::InstanceToCommit*>(that->instancesToCommit_.Dequeue(0))); + if (instanceToCommit.get() == NULL || that->workersShouldStop_) // that's the signal to exit the thread + { + LOG(INFO) << "Commit thread has completed"; + return; + } + + instanceToCommit->GetInstance()->Commit(instanceToCommit->IsSimulate()); } - - instanceToCommit->GetInstance()->Commit(instanceToCommit->IsSimulate()); + catch(const Orthanc::OrthancException& e) + { + boost::mutex::scoped_lock lock(that->commitExceptionMutex_); + that->commitException_.reset(new Orthanc::OrthancException(e)); + } + catch(...) + { + boost::mutex::scoped_lock lock(that->commitExceptionMutex_); + that->commitException_.reset(new Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Unknown error in CommitWorker")); + } } } void DownloadArea::CommitInternal(bool simulate) { + commitException_.reset(NULL); + commitThreads_.reserve(commitWorkerThreadsCount); for (uint32_t i = 0; i < commitWorkerThreadsCount; ++i) @@ -313,7 +324,6 @@ if (it->second != NULL) { instancesToCommit_.Enqueue(new DownloadArea::InstanceToCommit(it->second, simulate)); // transfers the ownership of the Instance to the queue - it->second = NULL; } else { @@ -323,6 +333,12 @@ } ClearThreads(); + + if (commitException_.get() != NULL) + { + LOG(ERROR) << "At least one of the commit threads failed with " << commitException_->What() << " " << commitException_->GetDetails(); + throw Orthanc::OrthancException(*commitException_); + } } void DownloadArea::ClearThreads()
--- a/Framework/DownloadArea.h Tue Dec 09 16:17:40 2025 +0100 +++ b/Framework/DownloadArea.h Tue Dec 09 18:12:15 2025 +0100 @@ -69,6 +69,10 @@ std::vector<boost::shared_ptr<boost::thread> > commitThreads_; Orthanc::SharedMessageQueue instancesToCommit_; bool workersShouldStop_; + + boost::mutex commitExceptionMutex_; + std::unique_ptr<Orthanc::OrthancException> commitException_; // in case an error occurs inside a commit thread + void Clear();
