Skip to content

Commit

Permalink
Added Test for Reload (G-Research#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
sammychinedu2ky authored Nov 29, 2023
1 parent ed29db8 commit ffcd671
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
env:
RUN_CONSUL_ENTERPRISE_TESTS: ${{env.RUN_CONSUL_ENTERPRISE_TESTS }}
CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }}
CONSUL_AGENT_CONFIG_PATH: ${{ github.workspace }}/Consul.Test/test_config.json
- name: Upload Consul logs
if: failure()
uses: actions/upload-artifact@v3
Expand Down
37 changes: 33 additions & 4 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 Down Expand Up @@ -1014,5 +1013,35 @@ public async Task Agent_Metrics()
Assert.NotNull(agentMetrics.Response.Points);
Assert.NotNull(agentMetrics.Response.Samples);
}

[SkippableFact]
public async Task Agent_Reload()
{
var cutOffVersion = SemanticVersion.Parse("1.14.0");
Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Agent_Reload` is only supported from Consul {cutOffVersion}");
string configFile = Environment.GetEnvironmentVariable("CONSUL_AGENT_CONFIG_PATH");
Skip.If(string.IsNullOrEmpty(configFile), "The CONSUL_AGENT_CONFIG_PATH environment variable was not set");
var initialConfig = System.IO.File.ReadAllText(configFile);
var udpatedConfig = initialConfig.Replace("TRACE", "DEBUG");
try
{
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, initialConfig);
await _client.Agent.Reload();
}
finally
{
System.IO.File.WriteAllText(configFile, initialConfig);
}
}
}
}
2 changes: 1 addition & 1 deletion 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
11 changes: 11 additions & 0 deletions Consul/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,17 @@ public Task<WriteResult> Leave(string node, CancellationToken ct = default)
/// Reload triggers a configuration reload for the agent we are connected to.
/// </summary>
/// <returns>An empty write result</returns>
public Task<WriteResult> Reload(CancellationToken ct = default)
{
return _client.PutNothing("/v1/agent/reload").Execute(ct);
}

/// <summary>
/// Reload triggers a configuration reload for the agent we are connected to.
/// </summary>
/// <param name="node">The node name to reload</param>
/// <returns>An empty write result</returns>
[Obsolete]
public Task<WriteResult> Reload(string node, CancellationToken ct = default)
{
return _client.PutNothing("/v1/agent/reload").Execute(ct);
Expand Down
4 changes: 3 additions & 1 deletion Consul/Interfaces/IAgentEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public interface IAgentEndpoint
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);
Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default);
Task<WriteResult> Reload(CancellationToken ct = default);
[Obsolete]
Task<WriteResult> Reload(string node, CancellationToken ct = default);
Task<QueryResult<AgentHostInfo>> GetAgentHostInfo(CancellationToken ct = default);
Task<WriteResult> Leave(string node, CancellationToken ct = default);
Task<WriteResult> Reload(string node, CancellationToken ct = default);
}
}

0 comments on commit ffcd671

Please sign in to comment.