public async Task MasterElectionIntegrationTest2() { DateTime Start = DateTime.UtcNow; Console.WriteLine("Start: " + Start.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK") + " (+0ms)"); var nodeA = new Master("A", 3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(20)); var nodeB = new Master("B", 3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(20)); var nodeC = new Master("C", 3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(20)); Link(nodeA, nodeB, nodeC); //the one that goes first is always elected if everyone else waits Assert.AreEqual("A", await nodeA.GetMaster()); Assert.AreEqual("A", await nodeB.GetMaster()); Assert.AreEqual("A", await nodeC.GetMaster()); nodeA.Connected = false; DateTime KillTime = DateTime.UtcNow; Console.WriteLine("Master Killed: " + KillTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK") + " (+" + KillTime.Subtract(Start).TotalMilliseconds + "ms)"); var leaseExpired = false; string master; while (!leaseExpired && nodeB.TryGetMaster(out master)) await Task.Yield(); DateTime LeaseExpireTime = DateTime.UtcNow; Console.WriteLine("Lease Expired: " + LeaseExpireTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK") + " (+" + LeaseExpireTime.Subtract(Start).TotalMilliseconds + "ms)"); master = await nodeB.GetMaster(); Console.WriteLine("New Master: " + master); DateTime End = DateTime.UtcNow; Console.WriteLine("New Master Elected: " + End.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK") + " (+" + End.Subtract(Start).TotalMilliseconds + "ms)"); }