wabbajack/Wabbajack.Server.Test/MetricsTests.cs

55 lines
2.1 KiB
C#
Raw Normal View History

2020-04-08 22:28:50 +00:00
using System;
2020-08-26 04:03:43 +00:00
using System.Net.Http.Headers;
2020-04-08 22:28:50 +00:00
using System.Threading.Tasks;
using Dapper;
2020-06-26 17:08:30 +00:00
using Wabbajack.Lib;
using Wabbajack.Server.DataLayer;
2020-05-09 13:22:02 +00:00
using Wabbajack.Server.DTOs;
2021-02-18 05:44:54 +00:00
using Wabbajack.Server.Services;
2020-04-08 22:28:50 +00:00
using Xunit;
using Xunit.Abstractions;
namespace Wabbajack.BuildServer.Test
{
public class MetricsTests : ABuildServerSystemTest
{
public MetricsTests(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output, fixture)
{
}
[Fact]
2020-05-09 13:22:02 +00:00
public async Task CanSendAndGetMetrics()
2020-04-08 22:28:50 +00:00
{
var action = "action_" + Guid.NewGuid().ToString();
var subject = "subject_" + Guid.NewGuid().ToString();
await Metrics.Send(action, subject);
var sql = Fixture.GetService<SqlService>();
var conn = await sql.Open();
var result = await conn.QueryFirstOrDefaultAsync<string>("SELECT Subject FROM dbo.Metrics WHERE Action = @Action",
new {Action = action});
Assert.Equal(subject, result);
2020-05-09 13:22:02 +00:00
2020-08-26 04:03:43 +00:00
using var response = await _client.GetAsync(MakeURL($"metrics/report/{action}"));
Assert.Equal(TimeSpan.FromHours(1), response.Headers.CacheControl.MaxAge);
2020-05-09 13:22:02 +00:00
// we'll just make sure this doesn't error, with limited data that's about all we can do atm
2021-02-17 05:46:05 +00:00
using var totalInstalls = await _client.GetAsync(MakeURL($"metrics/total_installs.html"));
Assert.True(totalInstalls.IsSuccessStatusCode);
using var totalUniqueInstalls = await _client.GetAsync(MakeURL($"metrics/total_unique_installs.html"));
Assert.True(totalUniqueInstalls.IsSuccessStatusCode);
using var dumpResponse = await _client.GetAsync(MakeURL("metrics/dump.json"));
Assert.True(dumpResponse.IsSuccessStatusCode);
var data = await dumpResponse.Content.ReadAsStringAsync();
Assert.NotEmpty(data);
2021-02-18 05:44:54 +00:00
var cache = Fixture.GetService<MetricsKeyCache>();
Assert.True(await cache.KeyCount() > 0);
2020-04-08 22:28:50 +00:00
}
}
}