Skip to content

Commit

Permalink
Added tests to detect pooled buffer leaks (Azure#10)
Browse files Browse the repository at this point in the history
* reorganized folders

* Added buffer management tests
  • Loading branch information
KrzysztofCwalina authored Nov 30, 2018
1 parent e45dfbd commit d58a31c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions Azure.Configuration.Test/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.Configuration.Test;
using Azure.Core.Testing;

namespace Azure.Configuration.Tests
{
Expand All @@ -29,20 +30,25 @@ public async Task SetKeyValue()
string connectionString = "Endpoint=https://contoso.azconfig.io;Id=b1d9b31;Secret=aabbccdd";
ConfigurationService.ParseConnectionString(connectionString, out var uri, out var credential, out var secret);

var service = new ConfigurationService(uri, credential, secret);

var transport = new SetKeyValueMockTransport();
transport.KeyValue = s_testKey;
transport.Responses.Add(HttpStatusCode.NotFound);
transport.Responses.Add(HttpStatusCode.OK);

var service = new ConfigurationService(uri, credential, secret);
service.Pipeline.Transport = transport;
var pool = new TestPool<byte>();
service.Pipeline.Pool = pool;

Response<KeyValue> added = await service.SetKeyValueAsync(s_testKey, CancellationToken.None);

Assert.AreEqual(s_testKey.Key, added.Result.Key);
Assert.AreEqual(s_testKey.Label, added.Result.Label);
Assert.AreEqual(s_testKey.ContentType, added.Result.ContentType);
Assert.AreEqual(s_testKey.Locked, added.Result.Locked);

added.Dispose();
Assert.AreEqual(0, pool.CurrentlyRented);
}

[Test]
Expand All @@ -51,13 +57,15 @@ public async Task GetKeyValue()
string connectionString = "Endpoint=https://contoso.azconfig.io;Id=b1d9b31;Secret=aabbccdd";
ConfigurationService.ParseConnectionString(connectionString, out var uri, out var credential, out var secret);

var service = new ConfigurationService(uri, credential, secret);

var transport = new GetKeyValueMockTransport();
transport.KeyValue = s_testKey;
transport.Responses.Add(HttpStatusCode.NotFound);
transport.Responses.Add(HttpStatusCode.OK);

var service = new ConfigurationService(uri, credential, secret);
service.Pipeline.Transport = transport;
var pool = new TestPool<byte>();
service.Pipeline.Pool = pool;

Response<KeyValue> added = await service.GetKeyValueAsync("test", default, CancellationToken.None);

Expand Down
2 changes: 1 addition & 1 deletion Azure.Configuration/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<Response<KeyValue>> SetKeyValueAsync(KeyValue setting, Cancell
}
}

public async Task<Response<KeyValue>> GetKeyValueAsync(string key, GetKeyValueOptions options, CancellationToken cancellation)
public async Task<Response<KeyValue>> GetKeyValueAsync(string key, GetKeyValueOptions options, CancellationToken cancellation)
{
if (string.IsNullOrEmpty(key)) {
throw new ArgumentNullException(nameof(key));
Expand Down

0 comments on commit d58a31c

Please sign in to comment.