Skip to content

Commit

Permalink
Fix up client configuration handling of waittime
Browse files Browse the repository at this point in the history
  • Loading branch information
highlyunavailable committed Mar 23, 2016
1 parent 38333c4 commit 2486298
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
* `ConsulClient` is now `IDisposable` and should have `Dispose()` called to
clean it up. It is still supposed to be used in a long-lived fashion, though.

## 2016-03-23
* Fix a bug where setting `ConsulClientConfiguration.WaitTime` would cause 400
Bad Request responses. Also converted `QueryOptions.WaitTime` to a nullable
timespan to match the `ConsulClientConfiguration` property of the same
name/purpose.

## 2016-03-19
* Fix a bug where the StatusCode was not being set correctly on some result
types.
Expand Down
18 changes: 18 additions & 0 deletions Consul.Test/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public async Task Client_SetQueryOptions()
Assert.Equal("12345", request.Params["token"]);
}

[Fact]
public async Task Client_SetClientOptions()
{
var config = new ConsulClientConfiguration()
{
Datacenter = "foo",
WaitTime = new TimeSpan(0, 0, 100),
Token = "12345"
};
var client = new ConsulClient(config);
var request = client.Get<KVPair>("/v1/kv/foo");

await Assert.ThrowsAsync<ConsulRequestException>(async () => await request.Execute());

Assert.Equal("foo", request.Params["dc"]);
Assert.Equal("1m40s", request.Params["wait"]);
Assert.Equal("12345", request.Params["token"]);
}
[Fact]
public async Task Client_SetWriteOptions()
{
Expand Down
11 changes: 5 additions & 6 deletions Consul/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ public class QueryOptions
Consistency = ConsistencyMode.Default,
Datacenter = string.Empty,
Token = string.Empty,
WaitIndex = 0,
WaitTime = TimeSpan.Zero
WaitIndex = 0
};

/// <summary>
Expand All @@ -266,7 +265,7 @@ public class QueryOptions
/// <summary>
/// WaitTime is used to bound the duration of a wait. Defaults to that of the Config, but can be overridden.
/// </summary>
public TimeSpan WaitTime { get; set; }
public TimeSpan? WaitTime { get; set; }

/// <summary>
/// Token is used to provide a per-request ACL token which overrides the agent's default token.
Expand Down Expand Up @@ -546,7 +545,7 @@ internal ConsulRequest(ConsulClient client, string url, HttpMethod method)
}
if (client.Config.WaitTime.HasValue)
{
Params["wait"] = client.Config.WaitTime.Value.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
Params["wait"] = client.Config.WaitTime.Value.ToGoDuration();
}
if (!string.IsNullOrEmpty(client.Config.Token))
{
Expand Down Expand Up @@ -675,9 +674,9 @@ protected override void ApplyOptions()
{
Params["index"] = Options.WaitIndex.ToString();
}
if (Options.WaitTime != TimeSpan.Zero)
if (Options.WaitTime.HasValue)
{
Params["wait"] = Options.WaitTime.ToGoDuration();
Params["wait"] = Options.WaitTime.Value.ToGoDuration();
}
if (!string.IsNullOrEmpty(Options.Token))
{
Expand Down

0 comments on commit 2486298

Please sign in to comment.