InfluxTest.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Net.Http;
  3. using System.Threading;
  4. using Xunit;
  5. namespace OhmGraphite.Test
  6. {
  7. public class InfluxTest
  8. {
  9. [Fact, Trait("Category", "integration")]
  10. public async void CanInsertIntoInflux()
  11. {
  12. var config = new InfluxConfig(new Uri("http://influx:8086"), "mydb", "my_user", "my_pass");
  13. using (var writer = new InfluxWriter(config, "my-pc"))
  14. using (var client = new HttpClient())
  15. {
  16. for (int attempts = 0; ; attempts++)
  17. {
  18. try
  19. {
  20. await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
  21. var resp = await client.GetAsync(
  22. "http://influx:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
  23. Assert.True(resp.IsSuccessStatusCode);
  24. var content = await resp.Content.ReadAsStringAsync();
  25. Assert.Contains("/intelcpu/0/temperature/0", content);
  26. break;
  27. }
  28. catch (Exception ex)
  29. {
  30. if (attempts >= 10)
  31. {
  32. throw;
  33. }
  34. Thread.Sleep(TimeSpan.FromSeconds(1));
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }