Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion Consul.Test/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class BaseFixture : IAsyncLifetime
c.Address = TestHelper.HttpUri;
});

var timeout = TimeSpan.FromSeconds(15);
var timeout = TimeSpan.FromSeconds(60);
var cancelToken = new CancellationTokenSource(timeout).Token;
Exception exception = null;
var firstIteration = true;
Expand Down Expand Up @@ -67,6 +67,9 @@ public class BaseFixture : IAsyncLifetime
// Workaround for https://github.com/hashicorp/consul/issues/15061
await client.Agent.GetAgentMetrics();

if ((await client.Coordinate.Nodes()).Response.Length == 0)
continue;

break;
}
catch (OperationCanceledException)
Expand Down
24 changes: 24 additions & 0 deletions Consul.Test/CoordinateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,29 @@ public async Task Coordinate_GetNodes()
// get an error. - from offical API.
Assert.NotNull(nodes);
}

[Fact]
public async Task Coordinate_GetNode()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous version of the test was better, we did actually use a real node name in the query before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that with the node name I was receiving errors in the base fixture class

var info = await _client.Agent.Self();
var nodesResult = await _client.Coordinate.Nodes();

Assert.NotNull(nodesResult);
Assert.NotEmpty(nodesResult.Response);

var nodes = nodesResult.Response;

var firstNode = nodes[0];

var nodeDetailsResult = await _client.Coordinate.Node(firstNode.Node);

Assert.NotNull(nodeDetailsResult);
Assert.NotEmpty(nodeDetailsResult.Response);

var nodeDetails = nodeDetailsResult.Response;

Assert.IsType<CoordinateEntry[]>(nodeDetails);
Assert.NotEmpty(nodeDetails);
}
}
}
Binary file added Consul.Test/consul_1.18.1_windows_386.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions Consul/Coordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ public Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationTo
{
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/nodes"), q).Execute(ct);
}

/// <summary>
/// Node returns the coordinates of a given node in the LAN pool.
/// </summary>
/// <param name="node">The node to query</param>"
/// <param name="ct">The cancellation token</param>"
/// <param name="q">Customized query options</param>"
/// <remarks>Node is used to return the coordinates of a given node in the LAN pool.</returns>
public Task<QueryResult<CoordinateEntry[]>> Node(string node, QueryOptions q, CancellationToken ct = default)
{
return _client.Get<CoordinateEntry[]>(string.Format("/v1/coordinate/node/{0}", node), q).Execute(ct);
}

public Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken ct = default)
{
return Node(node, QueryOptions.Default, ct);
}
}

public partial class ConsulClient : IConsulClient
Expand Down
2 changes: 2 additions & 0 deletions Consul/Interfaces/ICoordinateEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface ICoordinateEndpoint
{
Task<QueryResult<CoordinateDatacenterMap[]>> Datacenters(CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Nodes(CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Node(string node, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Node(string node, CancellationToken ct = default);
Task<QueryResult<CoordinateEntry[]>> Nodes(QueryOptions q, CancellationToken ct = default);
}
}