Fixes
This commit is contained in:
@@ -32,7 +32,7 @@ SiaCurlError CSiaCurl::CheckApiError(const json& result)
|
||||
{
|
||||
if ((msg.substr(0, 3) == "404"))
|
||||
{
|
||||
ret = SiaCurlError::InvalidRequestPath;
|
||||
ret = SiaCurlError::HttpError;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ SiaCurlError CSiaCurl::CheckHttpError(const std::string& result)
|
||||
SiaCurlError CSiaCurl::ProcessResponse(const int& res, const int& httpCode, const std::string& result, json& response) const
|
||||
{
|
||||
SiaCurlError ret;
|
||||
if ((res == CURLE_OK) && (httpCode == 200))
|
||||
if ((res == CURLE_OK) && ((httpCode >= 200) && (httpCode <300)))
|
||||
{
|
||||
ret = CheckHttpError(result);
|
||||
if (ApiSuccess(ret))
|
||||
@@ -73,6 +73,10 @@ SiaCurlError CSiaCurl::ProcessResponse(const int& res, const int& httpCode, cons
|
||||
{
|
||||
ret = SiaCurlError::NoResponse;
|
||||
}
|
||||
else if (httpCode)
|
||||
{
|
||||
ret = SiaCurlError::HttpError;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = SiaCurlError::UnknownFailure;
|
||||
|
@@ -14,7 +14,6 @@ public:
|
||||
ServerVersionMismatch,
|
||||
InvalidRequiredVersion,
|
||||
NoResponse,
|
||||
InvalidRequestPath,
|
||||
HttpError,
|
||||
UnknownFailure
|
||||
};
|
||||
|
@@ -134,7 +134,7 @@ void CMockSiad::Start(const SiadTestType& testType)
|
||||
_serverThread.reset(new std::thread([this,&startedEvent]()
|
||||
{
|
||||
bool started = false;
|
||||
bool active;
|
||||
bool active = true;
|
||||
std::mutex clientMutex;
|
||||
std::vector<CMockClient*> connected;
|
||||
std::vector<CMockClient*> disconnected;
|
||||
@@ -149,7 +149,7 @@ void CMockSiad::Start(const SiadTestType& testType)
|
||||
}
|
||||
};
|
||||
|
||||
do
|
||||
while (active)
|
||||
{
|
||||
SOCKET listenSocket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
@@ -159,7 +159,7 @@ void CMockSiad::Start(const SiadTestType& testType)
|
||||
sockAddr.sin_port = htons(_hostConfig.HostPort);
|
||||
|
||||
bool listening = ((listenSocket != INVALID_SOCKET) && (::bind(listenSocket, reinterpret_cast<const struct sockaddr *>(&sockAddr), sizeof(sockAddr)) != SOCKET_ERROR)) && (::listen(listenSocket, 1) != SOCKET_ERROR);
|
||||
while (listening && ((active = (::WaitForSingleObject(_stopEvent, 1) == WAIT_TIMEOUT))))
|
||||
while (listening && active)
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
@@ -195,6 +195,8 @@ void CMockSiad::Start(const SiadTestType& testType)
|
||||
listening = false;
|
||||
}
|
||||
}
|
||||
active = (::WaitForSingleObject(_stopEvent, 1) == WAIT_TIMEOUT);
|
||||
listening = listening && listening;
|
||||
}
|
||||
|
||||
closesocket(listenSocket);
|
||||
@@ -214,12 +216,14 @@ void CMockSiad::Start(const SiadTestType& testType)
|
||||
client->Close();
|
||||
}
|
||||
}
|
||||
} while (active);
|
||||
|
||||
active = active && (::WaitForSingleObject(_stopEvent, 1) == WAIT_TIMEOUT);
|
||||
}
|
||||
|
||||
ClearDisconnected();
|
||||
}));
|
||||
|
||||
::WaitForSingleObject(startedEvent, INFINITE);
|
||||
::WaitForSingleObject(startedEvent, 5000);
|
||||
::CloseHandle(startedEvent);
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ namespace UnitTests
|
||||
|
||||
json result;
|
||||
SiaCurlError err = s.Get(L"daemon/version", result);
|
||||
Assert::IsTrue(err == SiaCurlError::InvalidRequestPath);
|
||||
Assert::IsTrue(err == SiaCurlError::HttpError);
|
||||
}
|
||||
|
||||
TEST_METHOD(InvalidCharactersInPath)
|
||||
@@ -69,7 +69,7 @@ namespace UnitTests
|
||||
|
||||
json result;
|
||||
SiaCurlError err = s.Get(L"~~~^**()Z&%$#daemon/version", result);
|
||||
Assert::IsTrue(err == SiaCurlError::InvalidRequestPath);
|
||||
Assert::IsTrue(err == SiaCurlError::HttpError);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -23,6 +23,11 @@ namespace UnitTests
|
||||
});
|
||||
}
|
||||
|
||||
~CEventAccumulator()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
private:
|
||||
std::deque<std::shared_ptr<CEvent>> _events;
|
||||
std::mutex _eventMutex;
|
||||
@@ -35,6 +40,12 @@ namespace UnitTests
|
||||
}
|
||||
|
||||
public:
|
||||
void Clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_eventMutex);
|
||||
_events.clear();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool WaitForEvent(DWORD timeoutMs = 5000)
|
||||
{
|
||||
@@ -70,9 +81,10 @@ namespace UnitTests
|
||||
TEST_CLASS(UnitTests)
|
||||
{
|
||||
private:
|
||||
const SiaHostConfig hostConfig = { TEST_SERVER_AND_PORT, TEST_SERVER_VERSION };
|
||||
const SiaHostConfig hostConfig = { L"127.0.0.1", 9988, TEST_SERVER_VERSION };
|
||||
static std::unique_ptr<CMockSiad> siad;
|
||||
static CDebugConsumer _debugConsumer;
|
||||
static CEventAccumulator _eventAccumulator;
|
||||
|
||||
public:
|
||||
TEST_METHOD_INITIALIZE(Initialize)
|
||||
@@ -101,9 +113,8 @@ namespace UnitTests
|
||||
siad->Start(SiadTestType::UploadFile);
|
||||
try
|
||||
{
|
||||
CEventAccumulator eventAccumulator;
|
||||
|
||||
CEventSystem::EventSystem.Start();
|
||||
_eventAccumulator.Clear();
|
||||
|
||||
CSiaDriveConfig driveConfig;
|
||||
CSiaCurl siaCurl(hostConfig);
|
||||
@@ -113,15 +124,15 @@ namespace UnitTests
|
||||
CUploadManager uploadManager(siaCurl, &driveConfig);
|
||||
uploadManager.AddOrUpdate(L"/test1/test.rtf", L"./TestCacheFolder/test1/test.rtf");
|
||||
|
||||
Assert::IsTrue(eventAccumulator.WaitForEvent<NewUploadAdded>(5000));
|
||||
Assert::IsTrue(eventAccumulator.WaitForEvent<CreatingTemporarySiaDriveFile>(5000));
|
||||
Assert::IsTrue(eventAccumulator.WaitForEvent<RenamingTemporarySiaDriveFile>(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>());
|
||||
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)
|
||||
{
|
||||
@@ -136,4 +147,5 @@ namespace UnitTests
|
||||
|
||||
std::unique_ptr<CMockSiad> UnitTests::siad;
|
||||
CDebugConsumer UnitTests::_debugConsumer;
|
||||
CEventAccumulator UnitTests::_eventAccumulator;
|
||||
}
|
Reference in New Issue
Block a user