InfluxTest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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)
  29. {
  30. if (attempts >= 10)
  31. {
  32. throw;
  33. }
  34. Thread.Sleep(TimeSpan.FromSeconds(1));
  35. }
  36. }
  37. }
  38. }
  39. [Fact, Trait("Category", "integration")]
  40. public async void CanInsertIntoPasswordLessInfluxdb()
  41. {
  42. var config = new InfluxConfig(new Uri("http://influx-passwordless:8086"), "mydb", "my_user", null);
  43. using (var writer = new InfluxWriter(config, "my-pc"))
  44. using (var client = new HttpClient())
  45. {
  46. for (int attempts = 0; ; attempts++)
  47. {
  48. try
  49. {
  50. await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
  51. var resp = await client.GetAsync(
  52. "http://influx-passwordless:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature");
  53. Assert.True(resp.IsSuccessStatusCode);
  54. var content = await resp.Content.ReadAsStringAsync();
  55. Assert.Contains("/intelcpu/0/temperature/0", content);
  56. break;
  57. }
  58. catch (Exception)
  59. {
  60. if (attempts >= 10)
  61. {
  62. throw;
  63. }
  64. Thread.Sleep(TimeSpan.FromSeconds(1));
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }