1
0

Upload manager tests

This commit is contained in:
Scott E. Graves
2017-02-23 23:45:06 -06:00
parent ba5c089b43
commit b087392cf2
4 changed files with 123 additions and 9 deletions

View File

@@ -11,6 +11,7 @@ public:
public:
virtual String GetSingleLineMessage() const = 0;
virtual std::shared_ptr<CEvent> Clone() const = 0;
};
typedef std::shared_ptr<CEvent> CEventPtr;

View File

@@ -101,6 +101,11 @@ public:
{
return L"CreatingTemporarySiaDriveFile|SP|" + _siaPath + L"|FP|" + _filePath + L"|TSP|" + _tempSourcePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new CreatingTemporarySiaDriveFile(_siaPath, _filePath, _tempSourcePath));
}
};
class CreatingTemporarySiaDriveFileFailed :
@@ -130,6 +135,11 @@ public:
{
return L"CreatingTemporarySiaDriveFileFailed|SP|" + _siaPath + L"|FP|" + _filePath + L"|TSP|" + _tempSourcePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new CreatingTemporarySiaDriveFileFailed(_siaPath, _filePath, _tempSourcePath));
}
};
class DeleteSiaDriveFileFailed :
@@ -159,6 +169,11 @@ public:
{
return L"DeleteSiaDriveFileFailed|SP|" + _siaPath + L"|FP|" + _filePath + L"|SDP|" + _siaDriveFilePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new DeleteSiaDriveFileFailed(_siaPath, _filePath, _siaDriveFilePath));
}
};
class DeleteTemporarySiaDriveFileFailed :
@@ -188,6 +203,11 @@ public:
{
return L"DeleteTemporarySiaDriveFileFailed|SP|" + _siaPath + L"|FP|" + _filePath + L"|TSP|" + _tempSourcePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new DeleteTemporarySiaDriveFileFailed(_siaPath, _filePath, _tempSourcePath));
}
};
class RenamingTemporarySiaDriveFile :
@@ -219,6 +239,11 @@ public:
{
return L"RenamingTemporarySiaDriveFile|SP|" + _siaPath + L"|FP|" + _filePath + L"|TSP|" + _tempSourcePath + L"|SDP|" + _siaDriveFilePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new RenamingTemporarySiaDriveFile(_siaPath, _filePath, _tempSourcePath, _siaDriveFilePath));
}
};
class RenamingTemporarySiaDriveFileFailed :
@@ -250,6 +275,11 @@ public:
{
return L"RenamingTemporarySiaDriveFileFailed|SP|" + _siaPath + L"|FP|" + _filePath + L"|TSP|" + _tempSourcePath + L"|SDP|" + _siaDriveFilePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new RenamingTemporarySiaDriveFileFailed(_siaPath, _filePath, _tempSourcePath, _siaDriveFilePath));
}
};
class ExistingUploadFound :
@@ -279,6 +309,11 @@ public:
{
return L"ExistingUploadFound|SP|" + _siaPath + L"|FP|" + _filePath + L"|ST|" + CUploadManager::UploadStatusToString(_uploadStatus);
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new ExistingUploadFound(_siaPath, _filePath, _uploadStatus));
}
};
class NewUploadAdded :
@@ -308,6 +343,11 @@ public:
{
return L"NewUploadAdded|SP|" + _siaPath + L"|FP|" + _filePath + L"|SDP|" + _siaDriveFilePath;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new NewUploadAdded(_siaPath, _filePath, _siaDriveFilePath));
}
};
class SourceFileNotFound :
@@ -331,6 +371,11 @@ private:
const String _filePath;
public:
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new SourceFileNotFound(_siaPath, _filePath));
}
virtual String GetSingleLineMessage() const override
{
return L"SourceFileNotFound|SP|" + _siaPath + L"|FP|" + _filePath;

View File

@@ -734,7 +734,8 @@ Global
{B3DF927F-A1CE-4F50-A621-A4C3A06E4F8A}.RelWithDebInfo|x64.Build.0 = Release|x64
{B3DF927F-A1CE-4F50-A621-A4C3A06E4F8A}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{B3DF927F-A1CE-4F50-A621-A4C3A06E4F8A}.RelWithDebInfo|x86.Build.0 = Release|Win32
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x64.ActiveCfg = Debug|Win32
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x64.ActiveCfg = Debug|x64
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x64.Build.0 = Debug|x64
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x86.ActiveCfg = Debug|Win32
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.Debug|x86.Build.0 = Debug|Win32
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.DLL Debug - DLL OpenSSL - DLL LibSSH2|x64.ActiveCfg = Release|Win32
@@ -858,7 +859,8 @@ Global
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|Win32
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|Win32
{BE7EE71D-6608-36DD-9687-D84AAE20C0A3}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|Win32
{92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x64.ActiveCfg = Debug|Win32
{92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x64.ActiveCfg = Debug|x64
{92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x64.Build.0 = Debug|x64
{92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x86.ActiveCfg = Debug|Win32
{92EF9CAE-3F0C-31D5-9556-62586CC5072D}.Debug|x86.Build.0 = Debug|Win32
{92EF9CAE-3F0C-31D5-9556-62586CC5072D}.DLL Debug - DLL OpenSSL - DLL LibSSH2|x64.ActiveCfg = Release|Win32

View File

@@ -12,6 +12,61 @@ using namespace Sia::Api;
namespace UnitTests
{
class CEventAccumulator
{
public:
CEventAccumulator()
{
CEventSystem::EventSystem.AddEventConsumer([this](const CEvent& event)
{
this->ProcessEvent(event);
});
}
private:
std::deque<std::shared_ptr<CEvent>> _events;
std::mutex _eventMutex;
private:
void ProcessEvent(const CEvent& event)
{
std::lock_guard<std::mutex> l(_eventMutex);
_events.push_back(event.Clone());
}
public:
template<typename T>
bool WaitForEvent(DWORD timeoutMs = 5000)
{
bool found = false;
do
{
{
std::lock_guard<std::mutex> l(_eventMutex);
auto it = std::find_if(_events.begin(), _events.end(), [](const std::shared_ptr<CEvent> event)->bool
{
return (dynamic_cast<const T*>(event.get()) != nullptr);
});
found = it != _events.end();
}
if (!found && timeoutMs--)
{
::Sleep(1);
}
} while (!found && timeoutMs);
return found;
}
template<typename T>
bool Contains()
{
return WaitForEvent<T>(1);
}
};
TEST_CLASS(UnitTests)
{
private:
@@ -20,11 +75,6 @@ namespace UnitTests
static CDebugConsumer _debugConsumer;
public:
TEST_CLASS_INITIALIZE(ClassInit)
{
CEventSystem::EventSystem.Start();
}
TEST_METHOD_INITIALIZE(Initialize)
{
// Always delete DB before next test
@@ -37,11 +87,13 @@ namespace UnitTests
TEST_METHOD_CLEANUP(DestroyTest)
{
siad->Stop();
CEventSystem::EventSystem.Stop();
}
TEST_CLASS_CLEANUP(DestroyClass)
{
siad->Stop();
CEventSystem::EventSystem.Stop();
}
TEST_METHOD(AddOrUpdateNoExisting)
@@ -49,6 +101,10 @@ namespace UnitTests
siad->Start(SiadTestType::UploadFile);
try
{
CEventAccumulator eventAccumulator;
CEventSystem::EventSystem.Start();
CSiaDriveConfig driveConfig;
CSiaCurl siaCurl(hostConfig);
String version = siaCurl.GetServerVersion();
@@ -56,15 +112,25 @@ namespace UnitTests
CUploadManager uploadManager(siaCurl, &driveConfig);
uploadManager.AddOrUpdate(L"/test1/test.rtf", L"./TestCacheFolder/test1/test.rtf");
Sleep(5000);
Assert::IsTrue(eventAccumulator.WaitForEvent<NewUploadAdded>(5000));
Assert::IsTrue(eventAccumulator.WaitForEvent<CreatingTemporarySiaDriveFile>(5000));
Assert::IsTrue(eventAccumulator.WaitForEvent<RenamingTemporarySiaDriveFile>(5000));
Assert::IsFalse(eventAccumulator.Contains<DeleteSiaDriveFileFailed>());
Assert::IsFalse(eventAccumulator.Contains<RenamingTemporarySiaDriveFileFailed>());
Assert::IsFalse(eventAccumulator.Contains<DeleteTemporarySiaDriveFileFailed>());
Assert::IsFalse(eventAccumulator.Contains<CreatingTemporarySiaDriveFileFailed>());
Assert::IsFalse(eventAccumulator.Contains<CreatingTemporarySiaDriveFileFailed>());
}
catch (SQLite::Exception e)
{
siad->Stop();
throw;
CEventSystem::EventSystem.Stop();
}
siad->Stop();
CEventSystem::EventSystem.Stop();
}
};