Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit dfd5247

Browse files
Making these changes easier to test
1 parent 78837a0 commit dfd5247

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

script

src/GitHub.Api/Metrics/UsageTracker.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ namespace GitHub.Unity
88
{
99
class UsageTrackerSync : IUsageTracker
1010
{
11+
12+
#if DEVELOPER_BUILD
13+
protected internal const int MetrisReportTimeout = 30;
14+
#else
15+
protected internal const int MetrisReportTimeout = 3 * 60;
16+
#endif
17+
1118
private static ILogging Logger { get; } = LogHelper.GetLogger<UsageTracker>();
1219

1320
private static object _lock = new object();
@@ -44,7 +51,7 @@ public UsageTrackerSync(ISettings userSettings, IUsageLoader usageLoader,
4451

4552
Logger.Trace("userId:{0} instanceId:{1}", userId, instanceId);
4653
if (Enabled)
47-
RunTimer(3 * 60);
54+
RunTimer(MetrisReportTimeout);
4855
}
4956

5057
private void RunTimer(int seconds)

src/tests/TestWebServer/HttpServer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Net.Sockets;
99
using System.Text;
1010
using System.Threading;
11+
using Newtonsoft.Json;
1112

1213
namespace TestWebServer
1314
{
@@ -106,6 +107,18 @@ private void Process(HttpListenerContext context)
106107

107108
if (context.Request.Url.AbsolutePath == "/api/usage/unity")
108109
{
110+
var streamReader = new StreamReader(context.Request.InputStream);
111+
string body = null;
112+
using (streamReader)
113+
{
114+
body = streamReader.ReadToEnd();
115+
}
116+
117+
var parsedJson = JsonConvert.DeserializeObject(body);
118+
var formattedJson = JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
119+
120+
Logger.Info(formattedJson);
121+
109122
var json = new { result = "Cool unity usage" }.ToJson();
110123
context.Response.StatusCode = (int)HttpStatusCode.OK;
111124
context.Response.ContentLength64 = json.Length;

src/tests/TestWebServer/TestWebServer.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
35+
<HintPath>..\..\..\packages\Newtonsoft.Json.11.0.2\lib\net35\Newtonsoft.Json.dll</HintPath>
36+
</Reference>
3437
<Reference Include="System" />
3538
<Reference Include="System.Core" />
3639
<Reference Include="System.Xml.Linq" />
@@ -81,6 +84,7 @@
8184
<None Include="files\unity\releases\github-for-unity-99.2.0-beta1.unitypackage">
8285
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8386
</None>
87+
<None Include="packages.config" />
8488
</ItemGroup>
8589
<ItemGroup>
8690
<ProjectReference Include="..\..\GitHub.Api\GitHub.Api.csproj">
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net35" />
4+
</packages>

0 commit comments

Comments
 (0)