Commit 5abe60bf authored by Nick Craver's avatar Nick Craver

ConfigureAwait love for tests

parent 47301faa
...@@ -35,7 +35,7 @@ public void TestManualIncr() ...@@ -35,7 +35,7 @@ public void TestManualIncr()
public async Task<long?> ManualIncr(IDatabase connection, string key) public async Task<long?> ManualIncr(IDatabase connection, string key)
{ {
var oldVal = (long?)await connection.StringGetAsync(key); var oldVal = (long?)await connection.StringGetAsync(key).ConfigureAwait(false);
var newVal = (oldVal ?? 0) + 1; var newVal = (oldVal ?? 0) + 1;
var tran = connection.CreateTransaction(); var tran = connection.CreateTransaction();
{ // check hasn't changed { // check hasn't changed
...@@ -44,7 +44,7 @@ public void TestManualIncr() ...@@ -44,7 +44,7 @@ public void TestManualIncr()
tran.AddCondition(Condition.StringEqual(key, oldVal)); tran.AddCondition(Condition.StringEqual(key, oldVal));
tran.StringSetAsync(key, newVal); tran.StringSetAsync(key, newVal);
#pragma warning restore 4014 #pragma warning restore 4014
if (!await tran.ExecuteAsync()) return null; // aborted if (!await tran.ExecuteAsync().ConfigureAwait(false)) return null; // aborted
return newVal; return newVal;
} }
} }
......
...@@ -170,8 +170,7 @@ where Attribute.IsDefined(method, typeof(TestAttribute)) ...@@ -170,8 +170,7 @@ where Attribute.IsDefined(method, typeof(TestAttribute))
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class ActiveTestAttribute : Attribute public sealed class ActiveTestAttribute : Attribute
{ {
private readonly int count; public int Count { get; }
public int Count { get { return count; } }
public ActiveTestAttribute() : this(1) { } public ActiveTestAttribute() : this(1) { }
public ActiveTestAttribute(int count) { this.count = count; } public ActiveTestAttribute(int count) { this.Count = count; }
} }
\ No newline at end of file
...@@ -170,7 +170,7 @@ public async System.Threading.Tasks.Task TestConfigureAsync() ...@@ -170,7 +170,7 @@ public async System.Threading.Tasks.Task TestConfigureAsync()
{ {
Thread.Sleep(1000); Thread.Sleep(1000);
Debug.WriteLine("About to reconfigure....."); Debug.WriteLine("About to reconfigure.....");
await muxer.ConfigureAsync(); await muxer.ConfigureAsync().ConfigureAwait(false);
Debug.WriteLine("Reconfigured"); Debug.WriteLine("Reconfigured");
} }
} }
......
...@@ -70,15 +70,15 @@ public async void IncrDecrFloatingPointAsync() ...@@ -70,15 +70,15 @@ public async void IncrDecrFloatingPointAsync()
double sum = 0; double sum = 0;
foreach (var value in incr) foreach (var value in incr)
{ {
await db.StringIncrementAsync(key, value); await db.StringIncrementAsync(key, value).ConfigureAwait(false);
sum += value; sum += value;
} }
foreach (var value in decr) foreach (var value in decr)
{ {
await db.StringDecrementAsync(key, value); await db.StringDecrementAsync(key, value).ConfigureAwait(false);
sum -= value; sum -= value;
} }
var val = (double)await db.StringGetAsync(key); var val = (double)await db.StringGetAsync(key).ConfigureAwait(false);
Assert.IsTrue(Within(sum, val, 0.0001)); Assert.IsTrue(Within(sum, val, 0.0001));
} }
...@@ -146,15 +146,15 @@ public async void HashIncrDecrFloatingPointAsync() ...@@ -146,15 +146,15 @@ public async void HashIncrDecrFloatingPointAsync()
double sum = 0; double sum = 0;
foreach (var value in incr) foreach (var value in incr)
{ {
await db.HashIncrementAsync(key, field, value); await db.HashIncrementAsync(key, field, value).ConfigureAwait(false);
sum += value; sum += value;
} }
foreach (var value in decr) foreach (var value in decr)
{ {
await db.HashDecrementAsync(key, field, value); await db.HashDecrementAsync(key, field, value).ConfigureAwait(false);
sum -= value; sum -= value;
} }
var val = (double)await db.HashGetAsync(key, field); var val = (double)await db.HashGetAsync(key, field).ConfigureAwait(false);
Assert.IsTrue(Within(sum, val, 0.0001)); Assert.IsTrue(Within(sum, val, 0.0001));
} }
......
...@@ -18,7 +18,7 @@ public async void Execute() ...@@ -18,7 +18,7 @@ public async void Execute()
{ {
for(int i = 0; i < 100; i++) for(int i = 0; i < 100; i++)
{ {
Assert.AreEqual("ok", await DoStuff(conn)); Assert.AreEqual("ok", await DoStuff(conn).ConfigureAwait(false));
} }
} }
...@@ -30,13 +30,13 @@ private async Task<string> DoStuff(ConnectionMultiplexer conn) ...@@ -30,13 +30,13 @@ private async Task<string> DoStuff(ConnectionMultiplexer conn)
var timeout = Task.Delay(5000); var timeout = Task.Delay(5000);
var len = db.ListLengthAsync("list"); var len = db.ListLengthAsync("list");
if (await Task.WhenAny(timeout, len) != len) if (await Task.WhenAny(timeout, len).ConfigureAwait(false) != len)
{ {
return "Timeout getting length"; return "Timeout getting length";
} }
if ((await len) == 0) if ((await len.ConfigureAwait(false)) == 0)
{ {
db.ListRightPush("list", "foo", flags: CommandFlags.FireAndForget); db.ListRightPush("list", "foo", flags: CommandFlags.FireAndForget);
} }
...@@ -48,14 +48,14 @@ private async Task<string> DoStuff(ConnectionMultiplexer conn) ...@@ -48,14 +48,14 @@ private async Task<string> DoStuff(ConnectionMultiplexer conn)
var exec = tran.ExecuteAsync(); var exec = tran.ExecuteAsync();
// SWAP THESE TWO // SWAP THESE TWO
bool ok = await Task.WhenAny(exec, timeout) == exec; bool ok = await Task.WhenAny(exec, timeout).ConfigureAwait(false) == exec;
//bool ok = true; //bool ok = true;
if (ok) if (ok)
{ {
if (await exec) if (await exec.ConfigureAwait(false))
{ {
await Task.WhenAll(x, y, z); await Task.WhenAll(x, y, z).ConfigureAwait(false);
var db2 = conn.GetDatabase(); var db2 = conn.GetDatabase();
db2.HashGet("hash", "whatever"); db2.HashGet("hash", "whatever");
......
...@@ -447,7 +447,7 @@ public void LowAllocationEnumerable() ...@@ -447,7 +447,7 @@ public void LowAllocationEnumerable()
.ContinueWith( .ContinueWith(
async _ => async _ =>
{ {
return (string)(await db.StringGetAsync("foo" + i)); return (string)(await db.StringGetAsync("foo" + i).ConfigureAwait(false));
} }
); );
......
...@@ -109,7 +109,7 @@ private void Continue(Task task) ...@@ -109,7 +109,7 @@ private void Continue(Task task)
} }
private async void DoAwait(Task task) private async void DoAwait(Task task)
{ {
await task; await task.ConfigureAwait(false);
continuationThread = Environment.CurrentManagedThreadId; continuationThread = Environment.CurrentManagedThreadId;
evt.Set(); evt.Set();
} }
......
...@@ -333,12 +333,12 @@ public async void BasicTran() ...@@ -333,12 +333,12 @@ public async void BasicTran()
var g = db.KeyExists(key); var g = db.KeyExists(key);
Assert.AreEqual(10, await a); Assert.AreEqual(10, await a.ConfigureAwait(false));
Assert.AreEqual(15, await b); Assert.AreEqual(15, await b.ConfigureAwait(false));
Assert.AreEqual(15, (long)await c); Assert.AreEqual(15, (long)await c.ConfigureAwait(false));
Assert.IsTrue(await d); Assert.IsTrue(await d.ConfigureAwait(false));
Assert.IsTrue(await e); Assert.IsTrue(await e.ConfigureAwait(false));
Assert.IsFalse(await f); Assert.IsFalse(await f.ConfigureAwait(false));
Assert.IsFalse(g); Assert.IsFalse(g);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment