Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Test for Reload #265

Merged
merged 29 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
617491a
Added Test for Reload
sammychinedu2ky Nov 2, 2023
56be74f
style: fix whitespaces
octocat Nov 2, 2023
77e1359
edit
sammychinedu2ky Nov 2, 2023
f36989a
fix
sammychinedu2ky Nov 3, 2023
e8c24e7
fix
sammychinedu2ky Nov 3, 2023
8bef4df
style: fix whitespaces
octocat Nov 3, 2023
7ebc45e
fixed
sammychinedu2ky Nov 3, 2023
afb77a4
Update Consul.Test/AgentTest.cs
sammychinedu2ky Nov 3, 2023
ef7b3cd
Update Consul.Test/AgentTest.cs
sammychinedu2ky Nov 3, 2023
e948eb5
style: fix whitespaces
octocat Nov 3, 2023
69bf013
added changes
sammychinedu2ky Nov 3, 2023
5990d46
Merge branch 'master' into agentreload
sammychinedu2ky Nov 3, 2023
1a103f7
testing env
sammychinedu2ky Nov 6, 2023
1283946
Merge branch 'agentreload' of https://github.com/sammychinedu2ky/cons…
sammychinedu2ky Nov 6, 2023
10d55cd
testing env
sammychinedu2ky Nov 6, 2023
7d3bbf9
testing env
sammychinedu2ky Nov 6, 2023
98ccbad
test env
sammychinedu2ky Nov 6, 2023
55d7e57
test env
sammychinedu2ky Nov 6, 2023
3724680
test env
sammychinedu2ky Nov 6, 2023
0d0ce5f
test env
sammychinedu2ky Nov 6, 2023
a6a5f05
test env
sammychinedu2ky Nov 6, 2023
27a5f29
testing env
sammychinedu2ky Nov 6, 2023
ec545b7
testing env
sammychinedu2ky Nov 6, 2023
b1c600d
testing env
sammychinedu2ky Nov 6, 2023
99148ba
testing env
sammychinedu2ky Nov 6, 2023
aa0e3e9
changed github workflow
sammychinedu2ky Nov 6, 2023
51afe8f
Merge branch 'master' into agentreload
sammychinedu2ky Nov 29, 2023
38bb8b2
added extra skippable
sammychinedu2ky Nov 29, 2023
3d98503
edit
sammychinedu2ky Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 18 additions & 83 deletions Consul.Test/AgentTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// -----------------------------------------------------------------------
// <copyright file="AgentTest.cs" company="PlayFab Inc">
// Copyright 2015 PlayFab Inc.
// <copyright file="AgentTest.cs" company="G-Research Limited">
// Copyright 2020 G-Research Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -19,16 +18,12 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Consul.Filtering;
using NuGet.Versioning;
using Xunit;
using static System.Net.WebRequestMethods;

namespace Consul.Test
{
Expand Down Expand Up @@ -1009,83 +1004,23 @@ public async Task Agent_Metrics()
Assert.NotNull(agentMetrics.Response.Samples);
}

[Fact]
[SkippableFact]
public async Task Agent_Reload()
{
string config1 = @"
{
""ports"": {
""http"": 8499,
""dns"": -1,
""grpc"": -1,
""grpc_tls"": -1,
""serf_lan"": 8100,
""serf_wan"": -1,
""server"": 8200,
""sidecar_min_port"": 0,
""sidecar_max_port"": 0,
""expose_min_port"": 0,
""expose_max_port"": 0
}
}";
string config2 = @"
{
""ports"": {
""http"": 8499,
""dns"": -1,
""grpc"": -1,
""grpc_tls"": -1,
""serf_lan"": 8100,
""serf_wan"": -1,
""server"": 8200,
""sidecar_min_port"": 0,
""sidecar_max_port"": 0,
""expose_min_port"": 0,
""expose_max_port"": 0
},
""service"": {
""name"": ""redis"",
""port"": 1234,
""Meta"": { ""some"": ""meta"" }
}
}";
// Generate a random file name
string fileName = Path.Combine(Path.GetTempPath(), "random_config_" + Guid.NewGuid().ToString() + ".json");

// Write the JSON data to the file
System.IO.File.WriteAllText(fileName, config1);

string consulPath = Path.Combine(Directory.GetCurrentDirectory(), "consul.exe");

// Specify the command and arguments
string command = $"agent -dev -config-file \"{fileName}\"";

ProcessStartInfo startInfo = new ProcessStartInfo(consulPath)
{
Arguments = command,
UseShellExecute = false
};
using (Process process = new Process
{
StartInfo = startInfo
})
{
process.Start();
var client = new ConsulClient(c =>
{
c.Token = Guid.NewGuid().ToString();
c.Address = new Uri(" http://127.0.0.1:8499");
});
var services = await client.Agent.Services();
Assert.Empty(services.Response);
System.IO.File.WriteAllText(fileName, config2);
await client.Agent.Reload();
services = await client.Agent.Services();
Assert.True(services.Response.ContainsKey("redis"));
process.Kill();
}


string configFile = Environment.GetEnvironmentVariable("AgentConfig");
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
Skip.If(string.IsNullOrEmpty(configFile));
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
var intialConfig = System.IO.File.ReadAllText(configFile);
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
var udpatedConfig = intialConfig.Replace("TRACE", "DEBUG");
var agentDetails = await _client.Agent.Self();
var agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"];
Assert.Equal("TRACE", agentLogLevel.Value);
System.IO.File.WriteAllText(configFile, udpatedConfig);
await _client.Agent.Reload();
agentDetails = await _client.Agent.Self();
agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"];
Assert.Equal("DEBUG", agentLogLevel.Value);
System.IO.File.WriteAllText(configFile, intialConfig);
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
await _client.Agent.Reload();
}
}
}
5 changes: 1 addition & 4 deletions Consul.Test/Consul.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net5.0;net6.0;net7.0</TargetFrameworks>
Expand Down Expand Up @@ -33,8 +33,5 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="consul.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>