1
0

Try to clean-up properly after unit tests

This commit is contained in:
Scott E. Graves
2017-02-15 11:28:57 -06:00
parent 2932c434e9
commit edf726a727
19 changed files with 573 additions and 43 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,152 @@
"Sia Host"
"0.5"
{
"downloadcalls": 0,
"erroredcalls": 0,
"formcontractcalls": 0,
"renewcalls": 0,
"revisecalls": 0,
"recentrevisioncalls": 0,
"settingscalls": 0,
"unrecognizedcalls": 0,
"blockheight": 0,
"recentchange": [
137,
234,
215,
246,
113,
128,
162,
143,
91,
45,
234,
33,
63,
219,
182,
103,
59,
145,
74,
121,
1,
55,
90,
120,
3,
53,
73,
51,
126,
197,
218,
192
],
"announced": false,
"autoaddress": "",
"financialmetrics": {
"contractcount": 0,
"contractcompensation": "0",
"potentialcontractcompensation": "0",
"lockedstoragecollateral": "0",
"lostrevenue": "0",
"loststoragecollateral": "0",
"potentialstoragerevenue": "0",
"riskedstoragecollateral": "0",
"storagerevenue": "0",
"transactionfeeexpenses": "0",
"downloadbandwidthrevenue": "0",
"potentialdownloadbandwidthrevenue": "0",
"potentialuploadbandwidthrevenue": "0",
"uploadbandwidthrevenue": "0"
},
"publickey": {
"algorithm": "ed25519",
"key": "lTMXt28S5M5FkAwyMf8UCJF+ZEnfTjQLFCGs/4kJjJc="
},
"revisionnumber": 0,
"secretkey": [
147,
23,
32,
167,
207,
22,
186,
70,
141,
121,
52,
206,
29,
57,
207,
229,
254,
217,
236,
113,
25,
235,
127,
25,
112,
255,
168,
1,
130,
120,
26,
142,
149,
51,
23,
183,
111,
18,
228,
206,
69,
144,
12,
50,
49,
255,
20,
8,
145,
126,
100,
73,
223,
78,
52,
11,
20,
33,
172,
255,
137,
9,
140,
151
],
"settings": {
"acceptingcontracts": false,
"maxdownloadbatchsize": 17825792,
"maxduration": 25920,
"maxrevisebatchsize": 17825792,
"netaddress": "",
"windowsize": 144,
"collateral": "115740740740",
"collateralbudget": "2000000000000000000000000000000",
"maxcollateral": "100000000000000000000000000000",
"mincontractprice": "20000000000000000000000000",
"mindownloadbandwidthprice": "250000000000000",
"minstorageprice": "115740740740",
"minuploadbandwidthprice": "10000000000000"
},
"unlockhash": "000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69"
}

View File

@@ -0,0 +1,6 @@
"Sia Storage Manager"
"0.6.0"
{
"SectorSalt": "280618ece27645a22dc075d48938f33410b8056bc3aab3e2eb86dcb7f4fe7d0f",
"StorageFolders": null
}

View File

@@ -0,0 +1,91 @@
"Miner Settings"
"0.5.0"
{
"RecentChange": [
137,
234,
215,
246,
113,
128,
162,
143,
91,
45,
234,
33,
63,
219,
182,
103,
59,
145,
74,
121,
1,
55,
90,
120,
3,
53,
73,
51,
126,
197,
218,
192
],
"Height": 0,
"Target": [
0,
0,
0,
0,
32,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"Address": "000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69",
"BlocksFound": null,
"UnsolvedBlock": {
"parentid": "25f6e3b9295a61f69fcb956aca9f0076234ecf2e02d399db5448b6e22f26e81c",
"nonce": [
0,
0,
0,
0,
0,
0,
0,
0
],
"timestamp": 1433600000,
"minerpayouts": null,
"transactions": null
}
}

View File

@@ -0,0 +1,56 @@
"Contractor Persistence"
"0.5.2"
{
"Allowance": {
"funds": "0",
"hosts": 0,
"period": 0,
"renewwindow": 0
},
"BlockHeight": 0,
"CachedRevisions": null,
"Contracts": null,
"CurrentPeriod": 0,
"LastChange": [
137,
234,
215,
246,
113,
128,
162,
143,
91,
45,
234,
33,
63,
219,
182,
103,
59,
145,
74,
121,
1,
55,
90,
120,
3,
53,
73,
51,
126,
197,
218,
192
],
"OldContracts": null,
"RenewedIDs": {},
"FinancialMetrics": {
"contractspending": "0",
"downloadspending": "0",
"storagespending": "0",
"uploadspending": "0"
}
}

View File

@@ -0,0 +1,40 @@
"HostDB Persistence"
"0.5"
{
"AllHosts": null,
"ActiveHosts": null,
"LastChange": [
137,
234,
215,
246,
113,
128,
162,
143,
91,
45,
234,
33,
63,
219,
182,
103,
59,
145,
74,
121,
1,
55,
90,
120,
3,
53,
73,
51,
126,
197,
218,
192
]
}

View File

@@ -0,0 +1,40 @@
"Wallet Seed"
"0.4.0"
{
"UID": [
234,
179,
222,
70,
130,
85,
109,
55,
224,
207,
73,
71,
149,
106,
142,
209,
115,
191,
101,
219,
162,
98,
183,
114,
160,
122,
197,
33,
65,
169,
130,
144
],
"EncryptionVerification": "3fiegFXRw7lRFuNebhtOWdHfad9IVjwqiA4yScakWRwgt84qu0ZRsWjmYqAwyJLQ0JHPcAqu9xYuK6FN",
"Seed": "ibLaavbG7PgvlvsQbuUSa3udZknGVN4lrtWtVN/1et5/9mGY8vDw+e7EhkgXRZyEKEjAU8nztAmFiZ+l"
}

View File

@@ -0,0 +1,80 @@
"Wallet Settings"
"0.4.0"
{
"UID": [
113,
245,
186,
210,
209,
191,
36,
201,
81,
222,
226,
105,
185,
22,
6,
119,
12,
175,
124,
99,
238,
248,
20,
223,
93,
175,
1,
203,
127,
197,
251,
226
],
"EncryptionVerification": "4FQGlRV8zJ9SYD67UrRJKCxsF6hREVebOyQgm+zQgkIw6imwW1/TSn66NV/hD4VHFkWE9VJktzKV/Azr",
"PrimarySeedFile": {
"UID": [
234,
179,
222,
70,
130,
85,
109,
55,
224,
207,
73,
71,
149,
106,
142,
209,
115,
191,
101,
219,
162,
98,
183,
114,
160,
122,
197,
33,
65,
169,
130,
144
],
"EncryptionVerification": "3fiegFXRw7lRFuNebhtOWdHfad9IVjwqiA4yScakWRwgt84qu0ZRsWjmYqAwyJLQ0JHPcAqu9xYuK6FN",
"Seed": "ibLaavbG7PgvlvsQbuUSa3udZknGVN4lrtWtVN/1et5/9mGY8vDw+e7EhkgXRZyEKEjAU8nztAmFiZ+l"
},
"PrimarySeedProgress": 1,
"AuxiliarySeedFiles": null,
"UnseededKeys": null
}

View File

@@ -0,0 +1,93 @@
#include "stdafx.h"
#include <SiaCommon.h>
#include "UnitTestConfig.h"
std::uint16_t Daemon::_iter = 0;
Daemon::Daemon()
{
_i = _iter++;
Cleanup();
}
Daemon::~Daemon()
{
Stop();
Cleanup();
}
BOOL Daemon::DirectoryExists(const String& path)
{
DWORD dwAttrib = GetFileAttributes(path.c_str());
return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
void Daemon::Cleanup()
{
BOOL failed = TRUE;
String path;
path.resize(MAX_PATH + 1);
GetFullPathName((L"\"..\\..\\..\\..\\3rd-party\\Sia-v1.1.0-windows-amd64\\data" + std::to_wstring(_i)).c_str(), MAX_PATH, &path[0], nullptr);
while (failed)
{
PROCESS_INFORMATION pi2;
STARTUPINFO si2;
ZeroMemory(&si2, sizeof(si2));
si2.cb = sizeof(si2);
ZeroMemory(&pi2, sizeof(pi2));
String szCmdline = L"cmd.exe /c del /s /q \"" + path + L"\"";
CreateProcess(nullptr, &szCmdline[0], nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si2, &pi2);
if (!(failed = (pi2.hProcess == 0)))
{
WaitForSingleObject(pi2.hProcess, INFINITE);
CloseHandle(pi2.hProcess);
CloseHandle(pi2.hThread);
}
ZeroMemory(&si2, sizeof(si2));
si2.cb = sizeof(si2);
ZeroMemory(&pi2, sizeof(pi2));
szCmdline = L"cmd.exe /c rd /s /q \"" + path + L"\"";
CreateProcess(nullptr, &szCmdline[0], nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si2, &pi2);
if (!(failed = (pi2.hProcess == 0)))
{
WaitForSingleObject(pi2.hProcess, INFINITE);
CloseHandle(pi2.hProcess);
CloseHandle(pi2.hThread);
}
Sleep(100);
}
}
void Daemon::Start()
{
String path;
path.resize(MAX_PATH + 1);
GetFullPathName(L"\"..\\..\\..\\..\\3rd-party\\Sia-v1.1.0-windows-amd64\\", MAX_PATH, &path[0], nullptr);
String exec;
exec.resize(MAX_PATH + 1);
GetFullPathName(L"\"..\\..\\..\\..\\3rd-party\\Sia-v1.1.0-windows-amd64\\siad.exe", MAX_PATH, &exec[0], nullptr);
String szCmdline = L" -d .\\data" + std::to_wstring(_i) + L" --api-addr " + String(TEST_SERVER_HOST) + L":" + std::to_wstring(TEST_SERVER_PORT) + L" --no-bootstrap";
CreateProcess(exec.c_str(), &szCmdline[0], nullptr, nullptr, FALSE, 0, nullptr, path.c_str(), &si, &pi);
}
void Daemon::Stop()
{
if (pi.hProcess)
{
TerminateProcess(pi.hProcess, -1);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
}
}

View File

@@ -10,58 +10,26 @@ using namespace Sia::Api;
class Daemon
{
public:
~Daemon()
{
Stop();
}
Daemon();
public:
~Daemon();
private:
static std::uint16_t _iter;
std::uint16_t _i;
PROCESS_INFORMATION pi;
STARTUPINFO si;
private:
void Cleanup()
{
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
BOOL DirectoryExists(const String& path);
String szCmdline = L"cmd.exe /c del /s /q .\\data";
CreateProcess(nullptr, &szCmdline[0], nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &pi);
if (pi.hProcess)
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
}
void Cleanup();
public:
void Start()
{
Cleanup();
void Start();
String szCmdline = L"\"..\\..\\3rd-party\\Sia-v1.1.0-windows-amd64\\siad.exe\" -d .\\data --api-addr " + String(TEST_SERVER_HOST) + L":" + std::to_wstring(TEST_SERVER_PORT) + L" --no-bootstrap";
CreateProcess(nullptr, &szCmdline[0], nullptr, nullptr, TRUE, 0, nullptr, nullptr, &si, &pi);
}
void Stop()
{
if (pi.hProcess)
{
TerminateProcess(pi.hProcess, 0);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
Cleanup();
}
}
void Stop();
};
#define DAEMON_TEST() \
@@ -80,4 +48,4 @@ public:
}
#define DEFINE_DAEMON(class) Daemon class::_daemon
#define DEFINE_DAEMON(class) Daemon class::_daemon;

View File

@@ -182,6 +182,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="SiaCurlTests.cpp" />
<ClCompile Include="UnitTestConfig.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SiaDrive.Api\SiaDrive.Api.vcxproj">

View File

@@ -44,5 +44,8 @@
<ClCompile Include="SiaApiFileTreeTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UnitTestConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>