Skip to content

Commit ffcd671

Browse files
Added Test for Reload (#265)
1 parent ed29db8 commit ffcd671

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
env:
132132
RUN_CONSUL_ENTERPRISE_TESTS: ${{env.RUN_CONSUL_ENTERPRISE_TESTS }}
133133
CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }}
134+
CONSUL_AGENT_CONFIG_PATH: ${{ github.workspace }}/Consul.Test/test_config.json
134135
- name: Upload Consul logs
135136
if: failure()
136137
uses: actions/upload-artifact@v3

Consul.Test/AgentTest.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// -----------------------------------------------------------------------
2-
// <copyright file="AgentTest.cs" company="PlayFab Inc">
3-
// Copyright 2015 PlayFab Inc.
2+
// <copyright file="AgentTest.cs" company="G-Research Limited">
43
// Copyright 2020 G-Research Limited
54
//
6-
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// Licensed under the Apache License, Version 2.0 (the "License"),
76
// you may not use this file except in compliance with the License.
87
// You may obtain a copy of the License at
98
//
10-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1110
//
1211
// Unless required by applicable law or agreed to in writing, software
1312
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -1014,5 +1013,35 @@ public async Task Agent_Metrics()
10141013
Assert.NotNull(agentMetrics.Response.Points);
10151014
Assert.NotNull(agentMetrics.Response.Samples);
10161015
}
1016+
1017+
[SkippableFact]
1018+
public async Task Agent_Reload()
1019+
{
1020+
var cutOffVersion = SemanticVersion.Parse("1.14.0");
1021+
Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Agent_Reload` is only supported from Consul {cutOffVersion}");
1022+
string configFile = Environment.GetEnvironmentVariable("CONSUL_AGENT_CONFIG_PATH");
1023+
Skip.If(string.IsNullOrEmpty(configFile), "The CONSUL_AGENT_CONFIG_PATH environment variable was not set");
1024+
var initialConfig = System.IO.File.ReadAllText(configFile);
1025+
var udpatedConfig = initialConfig.Replace("TRACE", "DEBUG");
1026+
try
1027+
{
1028+
var agentDetails = await _client.Agent.Self();
1029+
var agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"];
1030+
Assert.Equal("TRACE", agentLogLevel.Value);
1031+
System.IO.File.WriteAllText(configFile, udpatedConfig);
1032+
1033+
await _client.Agent.Reload();
1034+
agentDetails = await _client.Agent.Self();
1035+
agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"];
1036+
Assert.Equal("DEBUG", agentLogLevel.Value);
1037+
1038+
System.IO.File.WriteAllText(configFile, initialConfig);
1039+
await _client.Agent.Reload();
1040+
}
1041+
finally
1042+
{
1043+
System.IO.File.WriteAllText(configFile, initialConfig);
1044+
}
1045+
}
10171046
}
10181047
}

Consul.Test/Consul.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net461;net5.0;net6.0;net7.0</TargetFrameworks>

Consul/Agent.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,17 @@ public Task<WriteResult> Leave(string node, CancellationToken ct = default)
868868
/// Reload triggers a configuration reload for the agent we are connected to.
869869
/// </summary>
870870
/// <returns>An empty write result</returns>
871+
public Task<WriteResult> Reload(CancellationToken ct = default)
872+
{
873+
return _client.PutNothing("/v1/agent/reload").Execute(ct);
874+
}
875+
876+
/// <summary>
877+
/// Reload triggers a configuration reload for the agent we are connected to.
878+
/// </summary>
879+
/// <param name="node">The node name to reload</param>
880+
/// <returns>An empty write result</returns>
881+
[Obsolete]
871882
public Task<WriteResult> Reload(string node, CancellationToken ct = default)
872883
{
873884
return _client.PutNothing("/v1/agent/reload").Execute(ct);

Consul/Interfaces/IAgentEndpoint.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public interface IAgentEndpoint
6363
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
6464
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);
6565
Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default);
66+
Task<WriteResult> Reload(CancellationToken ct = default);
67+
[Obsolete]
68+
Task<WriteResult> Reload(string node, CancellationToken ct = default);
6669
Task<QueryResult<AgentHostInfo>> GetAgentHostInfo(CancellationToken ct = default);
6770
Task<WriteResult> Leave(string node, CancellationToken ct = default);
68-
Task<WriteResult> Reload(string node, CancellationToken ct = default);
6971
}
7072
}

0 commit comments

Comments
 (0)